]>
git.saurik.com Git - apple/libc.git/blob - tests/stdtime.c
7 #include <TargetConditionals.h>
9 #include <darwintest.h>
11 T_DECL(strptime_PR_24428248
, "strptime parse day of year %j does not work correctly")
13 struct tm percent_j
= {0};
14 struct tm standard
= {0};
15 strptime("2007 80 0 0 15", "%Y %j %H %M %S", &percent_j
);
16 strptime("2007-03-21 0:0:15", "%Y-%m-%d %H:%M:%S", &standard
);
17 time_t percent_j_out
= mktime(&percent_j
);
18 time_t standard_out
= mktime(&standard
);
19 T_EXPECT_EQ(percent_j_out
, standard_out
, NULL
);
23 T_DECL(strptime_PR_5879606
, "alloca(strlen(input)) in strptime(\"%Z\")")
26 time_t t
= time(NULL
);
32 T_LOG("%s", asctime(&tm
));
33 T_ASSERT_NOTNULL(strptime("GMT", "%Z", &tm
), "strptime GMT");
34 T_LOG("%s", asctime(&tm
));
36 strftime(tz
, sizeof(tz
), "%Z", &tm
);
37 T_LOG("The current time zone name is: %s\n", tz
);
40 T_ASSERT_NOTNULL(strptime(tz
, "%Z", &tm
), "strptime local TZ name");
41 T_LOG("%s", asctime(&tm
));
43 T_QUIET
; T_ASSERT_NOTNULL((buf
= malloc(s
)), NULL
);
46 T_ASSERT_NULL(strptime(buf
, "%Z", &tm
), NULL
);
50 T_DECL(strptime_PR_6882179
, "date command fails with 'illegal time format'")
53 char buf
[] = "Tue May 12 18:19:41 PDT 2009";
55 T_ASSERT_NOTNULL(strptime(buf
, "%a %b %d %T %Z %Y", &tm
), NULL
);
57 T_EXPECT_EQ(tm
.tm_sec
, 0x29, NULL
);
58 T_EXPECT_EQ(tm
.tm_min
, 0x13, NULL
);
59 T_EXPECT_EQ(tm
.tm_hour
, 0x12, NULL
);
60 T_EXPECT_EQ(tm
.tm_mday
, 0xc, NULL
);
61 T_EXPECT_EQ(tm
.tm_mon
, 0x4, NULL
);
62 T_EXPECT_EQ(tm
.tm_year
, 0x6d, NULL
);
63 T_EXPECT_EQ(tm
.tm_wday
, 0x2, NULL
);
64 T_EXPECT_EQ(tm
.tm_yday
, 0x83, NULL
);
68 T_DECL(strptime_lukemftp
, "year parsing"){
70 setlocale(LC_ALL
, "C");
71 T_ASSERT_NOTNULL(strptime("20090505223446", "%Y%m%d%H%M%S", &tm
), NULL
);
74 T_DECL(strptime_five_digit_year
, "strptime(%Y) with a 5 digit year")
76 // POSIX conformance requires that %Y only use 4 characters, so use the
77 // field width to change that for this test.
78 char *timestr
= "20080922T020000";
80 bzero(&tm
, sizeof(tm
));
81 T_ASSERT_NOTNULL(strptime("10001", "%5Y", &tm
), NULL
);
82 T_EXPECT_EQ(tm
.tm_year
, 10001 - 1900, NULL
);
83 T_ASSERT_NOTNULL(strptime(timestr
, "%Y%m%dT%H%M%S", &tm
), NULL
);
86 T_DECL(strptime_PR_10842560
, "strptime() with %W and %U")
93 {"%Y:%U:%w:%H", "2012:6:0:23", "Sun Feb 05 2012 23:00"},
94 {"%Y:%w:%U:%H", "2012:0:6:23", "Sun Feb 05 2012 23:00"},
95 {"%U:%w:%Y:%H", "6:0:2012:23", "Sun Feb 05 2012 23:00"},
96 {"%U:%Y:%w:%H", "6:2012:0:23", "Sun Feb 05 2012 23:00"},
97 {"%w:%Y:%U:%H", "0:2012:6:23", "Sun Feb 05 2012 23:00"},
98 {"%w:%U:%Y:%H", "0:6:2012:23", "Sun Feb 05 2012 23:00"},
99 {"%Y:%V:%w:%H", "2012:6:0:23", "Sun Feb 12 2012 23:00"},
100 {"%Y:%w:%V:%H", "2012:0:6:23", "Sun Feb 12 2012 23:00"},
101 {"%V:%w:%Y:%H", "6:0:2012:23", "Sun Feb 12 2012 23:00"},
102 {"%V:%Y:%w:%H", "6:2012:0:23", "Sun Feb 12 2012 23:00"},
103 {"%w:%Y:%V:%H", "0:2012:6:23", "Sun Feb 12 2012 23:00"},
104 {"%w:%V:%Y:%H", "0:6:2012:23", "Sun Feb 12 2012 23:00"},
105 {"%Y:%W:%w:%H", "2012:6:0:23", "Sun Feb 12 2012 23:00"},
106 {"%Y:%w:%W:%H", "2012:0:6:23", "Sun Feb 12 2012 23:00"},
107 {"%W:%w:%Y:%H", "6:0:2012:23", "Sun Feb 12 2012 23:00"},
108 {"%W:%Y:%w:%H", "6:2012:0:23", "Sun Feb 12 2012 23:00"},
109 {"%w:%Y:%W:%H", "0:2012:6:23", "Sun Feb 12 2012 23:00"},
110 {"%w:%W:%Y:%H", "0:6:2012:23", "Sun Feb 12 2012 23:00"},
111 {"%Y:%U:%w:%H", "2011:6:0:23", "Sun Feb 06 2011 23:00"},
112 {"%Y:%U:%w:%H", "2010:6:0:23", "Sun Feb 07 2010 23:00"},
113 {"%Y:%U:%w:%H", "2009:6:0:23", "Sun Feb 08 2009 23:00"},
114 {"%Y:%U:%w:%H", "2008:6:0:23", "Sun Feb 10 2008 23:00"},
115 {"%Y:%U:%w:%H", "2007:6:0:23", "Sun Feb 11 2007 23:00"},
116 {"%Y:%U:%w:%H", "2006:6:0:23", "Sun Feb 05 2006 23:00"},
117 {"%Y:%V:%w:%H", "2011:6:0:23", "Sun Feb 13 2011 23:00"},
118 {"%Y:%V:%w:%H", "2010:6:0:23", "Sun Feb 14 2010 23:00"},
119 {"%Y:%V:%w:%H", "2009:6:0:23", "Sun Feb 08 2009 23:00"},
120 {"%Y:%V:%w:%H", "2008:6:0:23", "Sun Feb 10 2008 23:00"},
121 {"%Y:%V:%w:%H", "2007:6:0:23", "Sun Feb 11 2007 23:00"},
122 {"%Y:%V:%w:%H", "2006:6:0:23", "Sun Feb 12 2006 23:00"},
123 {"%Y:%W:%w:%H", "2011:6:0:23", "Sun Feb 13 2011 23:00"},
124 {"%Y:%W:%w:%H", "2010:6:0:23", "Sun Feb 14 2010 23:00"},
125 {"%Y:%W:%w:%H", "2009:6:0:23", "Sun Feb 15 2009 23:00"},
126 {"%Y:%W:%w:%H", "2008:6:0:23", "Sun Feb 17 2008 23:00"},
127 {"%Y:%W:%w:%H", "2007:6:0:23", "Sun Feb 11 2007 23:00"},
128 {"%Y:%W:%w:%H", "2006:6:0:23", "Sun Feb 12 2006 23:00"},
131 const struct test
*tp
;
133 for(tp
= test
; tp
->fmt
; tp
++){
138 memset(&Tm
,0,sizeof(Tm
));
139 s
= strptime(tp
->str
, tp
->fmt
, &Tm
);
140 T_QUIET
; T_EXPECT_NOTNULL(s
, "strptime() should return non-NULL");
142 strftime(Buf
, sizeof(Buf
), "%a %b %d %Y %R", &Tm
);
143 T_EXPECT_EQ_STR(Buf
, tp
->result
, "%s | %s", tp
->fmt
, tp
->str
);
148 #if !TARGET_OS_BRIDGE
149 T_DECL(strptime_asctime
, "strptime->asctime",
150 T_META_REQUIRES_OS_VARIANT_NOT("IsDarwinOS")) {
152 "Sun, 6 Apr 2003 03:30:00 -0500",
153 "Sun, 6 Apr 2003 04:30:00 -0500",
154 "Sun, 6 Apr 2003 05:30:00 -0500",
155 "Sun, 6 Apr 2003 06:30:00 -0500",
156 "Wed, 17 Sep 2003 13:30:00 -0500",
157 "Sun, 26 Oct 2003 03:30:00 -0500",
158 "Sun, 26 Oct 2003 04:30:00 -0500",
159 "Sun, 26 Oct 2003 05:30:00 -0500",
160 "Sun, 26 Oct 2003 06:30:00 -0500",
165 "Sun Apr 6 00:30:00 2003\n",
166 "Sun Apr 6 01:30:00 2003\n",
167 "Sun Apr 6 03:30:00 2003\n",
168 "Sun Apr 6 04:30:00 2003\n",
169 "Wed Sep 17 11:30:00 2003\n",
170 "Sun Oct 26 01:30:00 2003\n",
171 "Sun Oct 26 01:30:00 2003\n",
172 "Sun Oct 26 02:30:00 2003\n",
173 "Sun Oct 26 03:30:00 2003\n",
180 strptime(test
[i
], "%a, %d %b %Y %H:%M:%S %z", &tm
);
181 T_EXPECT_EQ_STR(result
[i
], asctime(&tm
), "%s", test
[i
]);