1 /********************************************************************
2  *   © 2016 and later: Unicode, Inc. and others.
3  *   License & terms of use: http://www.unicode.org/copyright.html
4  *************************************************************************
5  *************************************************************************
6  * COPYRIGHT:
7  * Copyright (c) 1999-2003, International Business Machines Corporation and
8  * others. All Rights Reserved.
9  *************************************************************************/
10 
11 #include "unicode/unistr.h"
12 #include "unicode/calendar.h"
13 #include "unicode/datefmt.h"
14 #include "unicode/uclean.h"
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include "util.h"
18 
19 /**
20  * If the ID supplied to TimeZone is not a valid system ID,
21  * TimeZone::createTimeZone() will return a GMT zone object.  In order
22  * to detect this error, we check the ID of the returned zone against
23  * the ID we requested.  If they don't match, we fail with an error.
24  */
createZone(const UnicodeString & id)25 TimeZone* createZone(const UnicodeString& id) {
26     UnicodeString str;
27     TimeZone* zone = TimeZone::createTimeZone(id);
28     if (zone->getID(str) != id) {
29         delete zone;
30         printf("Error: TimeZone::createTimeZone(");
31         uprintf(id);
32         printf(") returned zone with ID ");
33         uprintf(str);
34         printf("\n");
35         exit(1);
36     }
37     return zone;
38 }
39 
main(int argc,char ** argv)40 int main(int argc, char **argv) {
41 
42     UErrorCode status = U_ZERO_ERROR;
43     UnicodeString str;
44 
45     // The languages in which we will display the date
46     static char* LANGUAGE[] = {
47         "en", "de", "fr"
48     };
49     static const int32_t N_LANGUAGE = sizeof(LANGUAGE)/sizeof(LANGUAGE[0]);
50 
51     // The time zones in which we will display the time
52     static char* TIMEZONE[] = {
53         "America/Los_Angeles",
54         "America/New_York",
55         "Europe/Paris",
56         "Europe/Berlin"
57     };
58     static const int32_t N_TIMEZONE = sizeof(TIMEZONE)/sizeof(TIMEZONE[0]);
59 
60     for (int32_t i=0; i<N_LANGUAGE; ++i) {
61         Locale loc(LANGUAGE[i]);
62 
63         // Display the formatted date string
64         printf("Date (%s)\n", LANGUAGE[i]);
65     }
66 
67     printf("Exiting successfully\n");
68     u_cleanup();
69     return 0;
70 }
71