blob: 99ea4feb1e4a9fe41f39ed2ca7baebbd331988c6 [file] [log] [blame]
vlmfa67ddc2004-06-03 03:38:44 +00001#define __NO_ASN_TABLE__
2#include "../UTCTime.c"
3#define __NO_ASSERT_H__
4#include "../GeneralizedTime.c"
5#include "../constraints.c"
6
7static void
vlmd0c608e2004-08-07 03:51:43 +00008check(char *time_str, time_t sample, int as_gmt) {
vlmfa67ddc2004-06-03 03:38:44 +00009 UTCTime_t gt;
10 struct tm tm;
11 time_t tloc;
12
13 gt.buf = time_str;
14 gt.size = strlen(time_str);
15
vlmd0c608e2004-08-07 03:51:43 +000016 tloc = asn_UT2time(&gt, &tm, as_gmt);
vlmfa67ddc2004-06-03 03:38:44 +000017 printf("[%s] -> %ld == %ld\n", time_str, (long)tloc, (long)sample);
18 if(tloc != -1)
19 printf("\t%d-%d-%dT%02d:%02d:%02d %ld\n",
20 tm.tm_year + 1900,
21 tm.tm_mon + 1,
22 tm.tm_mday,
23 tm.tm_hour,
24 tm.tm_min,
25 tm.tm_sec,
26 tm.tm_gmtoff
27 );
28 assert(tloc == sample);
vlmd0c608e2004-08-07 03:51:43 +000029
30 assert(tloc == -1 || as_gmt == 0 || tm.tm_gmtoff == 0);
31
32 if(as_gmt) check(time_str, sample, as_gmt);
vlmfa67ddc2004-06-03 03:38:44 +000033}
34
35int
36main(int ac, char **av) {
37
vlmd0c608e2004-08-07 03:51:43 +000038 check("0401250", -1, 0);
39 check("0401250930", -1, 0); /* "Z" or "(+|-)hhmm" required */
40 check("04012509300", -1, 0);
41 check("040125093000-", -1, 0);
42 check("040125093007-0", -1, 0);
43 check("040125093007-080", -1, 0);
44 check("0401250930.01Z", -1, 0);
vlmfa67ddc2004-06-03 03:38:44 +000045
vlmd0c608e2004-08-07 03:51:43 +000046 check("040125093007Z", 1075023007, 0);
47 check("040125093007+00", 1075023007, 0);
48 check("040125093007-0800", 1075051807, 0);
vlmfa67ddc2004-06-03 03:38:44 +000049
50 if(ac > 1) {
51 /* These will be valid only inside PST time zone */
vlmd0c608e2004-08-07 03:51:43 +000052 check("040125093007", 1075051807, 0);
53 check("040125093000,01", 1075051800, 0);
54 check("040125093000,1234", 1075051800, 0);
vlmfa67ddc2004-06-03 03:38:44 +000055 }
56
57 return 0;
58}
vlmd0c608e2004-08-07 03:51:43 +000059
60
61/*
62 * Dummy function.
63 */
64
65der_enc_rval_t
66OCTET_STRING_encode_der(asn1_TYPE_descriptor_t *td, void *ptr, int tag_mode, ber_tlv_tag_t tag, asn_app_consume_bytes_f *cb, void *app_key) {
67 der_enc_rval_t erval;
68 return erval;
69}