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