1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 * This test program should eventually become a full-blown test for
8 * PR_ParseTimeString. Right now it just verifies that PR_ParseTimeString
9 * doesn't crash on an out-of-range time string (bug 480740).
19 PRBool debug_mode
= PR_TRUE
;
21 static char *dayOfWeek
[] =
22 { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
23 static char *month
[] =
24 { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
25 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???"
28 static void PrintExplodedTime(const PRExplodedTime
*et
) {
30 PRInt32 hourOffset
, minOffset
;
33 /* Print day of the week, month, day, hour, minute, and second */
34 if (debug_mode
) printf("%s %s %ld %02ld:%02ld:%02ld ",
35 dayOfWeek
[et
->tm_wday
], month
[et
->tm_month
], et
->tm_mday
,
36 et
->tm_hour
, et
->tm_min
, et
->tm_sec
);
39 totalOffset
= et
->tm_params
.tp_gmt_offset
+ et
->tm_params
.tp_dst_offset
;
40 if (totalOffset
== 0) {
46 if (totalOffset
< 0) {
47 totalOffset
= -totalOffset
;
50 hourOffset
= totalOffset
/ 3600;
51 minOffset
= (totalOffset
% 3600) / 60;
53 printf("%s%02ld%02ld ", sign
, hourOffset
, minOffset
);
59 printf("%hd", et
->tm_year
);
63 int main(int argc
, char **argv
)
68 char *sp1
= "Sat, 1 Jan 3001 00:00:00"; /* no time zone */
69 char *sp2
= "Fri, 31 Dec 3000 23:59:60"; /* no time zone, not normalized */
71 #if _MSC_VER >= 1400 && !defined(WINCE)
72 /* Run this test in the US Pacific Time timezone. */
73 _putenv_s("TZ", "PST8PDT");
77 rv
= PR_ParseTimeString(sp1
, PR_FALSE
, &ct
);
78 printf("rv = %d\n", rv
);
79 PR_ExplodeTime(ct
, PR_GMTParameters
, &et
);
80 PrintExplodedTime(&et
);
83 rv
= PR_ParseTimeString(sp2
, PR_FALSE
, &ct
);
84 printf("rv = %d\n", rv
);
85 PR_ExplodeTime(ct
, PR_GMTParameters
, &et
);
86 PrintExplodedTime(&et
);