]>
git.saurik.com Git - apple/icu.git/blob - icuSources/test/compat/tzdate.c
2 **********************************************************************
3 * Copyright (C) 2007-2007, International Business Machines
4 * Corporation and others. All Rights Reserved.
5 **********************************************************************
11 **********************************************************************
19 #include "unicode/utypes.h"
20 #include "unicode/ustring.h"
21 #include "unicode/uclean.h"
23 #include "unicode/ucnv.h"
24 #include "unicode/udat.h"
25 #include "unicode/ucal.h"
30 #define OFFSET_MONTH 1
32 int64_t getSystemCurrentTime(char* systime
, int year
, int month
, int day
, int hour
, int minute
, int useCurrentTime
);
33 void getICUCurrentTime(char* icutime
, double timeToCheck
);
34 void printTime(char* systime
, char* icutime
);
36 int main(int argc
, char** argv
) {
39 int year
, month
, day
, hour
, minute
;
44 sysyear
= year
= month
= day
= 0;
47 fprintf(stderr
, "Not enough arguments\n");
52 month
= atoi(argv
[2]);
55 minute
= atoi(argv
[5]);
56 useCurrentTime
= atoi(argv
[6]);
58 /* format year for system time */
59 sysyear
= year
- 1900;
61 systemtime
= getSystemCurrentTime(systime
, sysyear
, month
, day
, hour
, minute
, useCurrentTime
);
62 getICUCurrentTime(icutime
, systemtime
* U_MILLIS_PER_SECOND
);
64 /* print out the times if failed */
65 if (strcmp(systime
, icutime
) != 0) {
67 printTime(systime
, icutime
);
73 void getICUCurrentTime(char* icutime
, double timeToCheck
) {
77 UDateFormatStyle style
= UDAT_RELATIVE
;
78 UErrorCode status
= U_ZERO_ERROR
;
82 fmt
= udat_open(style
, style
, 0, tz
, -1,NULL
,0, &status
);
84 len
= udat_format(fmt
, timeToCheck
, 0, len
, 0, &status
);
86 if (status
== U_BUFFER_OVERFLOW_ERROR
)
87 status
= U_ZERO_ERROR
;
89 s
= (UChar
*) malloc(sizeof(UChar
) * (len
+1));
94 udat_format(fmt
, timeToCheck
, s
, len
+ 1, 0, &status
);
96 if (U_FAILURE(status
))
99 /* +1 to NULL terminate */
100 for(i
= 0; i
< len
+1; i
++) {
101 icutime
[i
] = (char)s
[i
];
109 int64_t getSystemCurrentTime(char* systime
, int year
, int month
, int day
, int hour
, int minute
, int useCurrentTime
) {
115 ts
= *localtime(&now
);
118 memset(&ts
, 0, sizeof(ts
));
120 ts
.tm_mon
= month
- OFFSET_MONTH
;
126 ts
= *localtime(&now
);
129 /* Format the string */
130 strftime(systime
, sizeof(char) * 80, "%Y%m%d %I:%M %p", &ts
);
135 void printTime(char* systime
, char* icutime
) {
136 printf("System Time: %s\n", systime
);
137 printf("ICU Time: %s\n", icutime
);
138 printf("STD=%s DST=%s OFFSET=%d\n", uprv_tzname(0), uprv_tzname(1), uprv_timezone());