blob: e1c25565c24fd813b0d829e0d135a67ce4d495ce [file] [log] [blame]
Lev Walkin4eceeba2007-07-23 06:48:26 +00001#include <stdio.h>
2#include <assert.h>
3#include <time.h>
4
Lev Walkin44212662004-08-19 13:26:54 +00005#include <GeneralizedTime.c>
Lev Walkin4eceeba2007-07-23 06:48:26 +00006#include <UTCTime.h>
Lev Walkinf15320b2004-06-03 03:38:44 +00007
8static void
Lev Walkin0aca3852004-08-07 03:51:43 +00009check(char *time_str, time_t sample, int as_gmt) {
Lev Walkinf15320b2004-06-03 03:38:44 +000010 UTCTime_t gt;
11 struct tm tm;
12 time_t tloc;
13
Lev Walkin535612a2005-07-03 05:32:40 +000014 gt.buf = (uint8_t *)time_str;
Lev Walkinf15320b2004-06-03 03:38:44 +000015 gt.size = strlen(time_str);
16
Lev Walkin0aca3852004-08-07 03:51:43 +000017 tloc = asn_UT2time(&gt, &tm, as_gmt);
Lev Walkinf15320b2004-06-03 03:38:44 +000018 printf("[%s] -> %ld == %ld\n", time_str, (long)tloc, (long)sample);
19 if(tloc != -1)
20 printf("\t%d-%d-%dT%02d:%02d:%02d %ld\n",
21 tm.tm_year + 1900,
22 tm.tm_mon + 1,
23 tm.tm_mday,
24 tm.tm_hour,
25 tm.tm_min,
26 tm.tm_sec,
Lev Walkina460ba32004-10-20 15:40:04 +000027 GMTOFF(tm)
Lev Walkinf15320b2004-06-03 03:38:44 +000028 );
29 assert(tloc == sample);
Lev Walkin0aca3852004-08-07 03:51:43 +000030
Lev Walkina460ba32004-10-20 15:40:04 +000031 assert(tloc == -1 || as_gmt == 0 || GMTOFF(tm) == 0);
Lev Walkin0aca3852004-08-07 03:51:43 +000032
33 if(as_gmt) check(time_str, sample, as_gmt);
Lev Walkinf15320b2004-06-03 03:38:44 +000034}
35
36int
37main(int ac, char **av) {
38
Lev Walkin44212662004-08-19 13:26:54 +000039 (void)av;
40
Lev Walkin0aca3852004-08-07 03:51:43 +000041 check("0401250", -1, 0);
42 check("0401250930", -1, 0); /* "Z" or "(+|-)hhmm" required */
43 check("04012509300", -1, 0);
44 check("040125093000-", -1, 0);
45 check("040125093007-0", -1, 0);
46 check("040125093007-080", -1, 0);
47 check("0401250930.01Z", -1, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000048
Lev Walkin0aca3852004-08-07 03:51:43 +000049 check("040125093007Z", 1075023007, 0);
50 check("040125093007+00", 1075023007, 0);
51 check("040125093007-0800", 1075051807, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000052
53 if(ac > 1) {
54 /* These will be valid only inside PST time zone */
Lev Walkin0aca3852004-08-07 03:51:43 +000055 check("040125093007", 1075051807, 0);
56 check("040125093000,01", 1075051800, 0);
57 check("040125093000,1234", 1075051800, 0);
Lev Walkinf15320b2004-06-03 03:38:44 +000058 }
59
60 return 0;
61}
Lev Walkin0aca3852004-08-07 03:51:43 +000062