Wed, 31 Dec 2014 07:53:36 +0100
Correct small whitespace inconsistency, lost while renaming variables.
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/. */
6 /*
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).
10 */
12 #include "prtime.h"
14 #include <time.h>
15 #include <stdio.h>
16 #include <stdlib.h>
17 #include <string.h>
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", "???" };
27 static void PrintExplodedTime(const PRExplodedTime *et) {
28 PRInt32 totalOffset;
29 PRInt32 hourOffset, minOffset;
30 const char *sign;
32 /* Print day of the week, month, day, hour, minute, and second */
33 if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
34 dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
35 et->tm_hour, et->tm_min, et->tm_sec);
37 /* Print time zone */
38 totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
39 if (totalOffset == 0) {
40 if (debug_mode) printf("UTC ");
41 } else {
42 sign = "+";
43 if (totalOffset < 0) {
44 totalOffset = -totalOffset;
45 sign = "-";
46 }
47 hourOffset = totalOffset / 3600;
48 minOffset = (totalOffset % 3600) / 60;
49 if (debug_mode)
50 printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
51 }
53 /* Print year */
54 if (debug_mode) printf("%hd", et->tm_year);
55 }
57 int main(int argc, char **argv)
58 {
59 PRTime ct;
60 PRExplodedTime et;
61 PRStatus rv;
62 char *sp1 = "Sat, 1 Jan 3001 00:00:00"; /* no time zone */
63 char *sp2 = "Fri, 31 Dec 3000 23:59:60"; /* no time zone, not normalized */
65 #if _MSC_VER >= 1400 && !defined(WINCE)
66 /* Run this test in the US Pacific Time timezone. */
67 _putenv_s("TZ", "PST8PDT");
68 _tzset();
69 #endif
71 rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
72 printf("rv = %d\n", rv);
73 PR_ExplodeTime(ct, PR_GMTParameters, &et);
74 PrintExplodedTime(&et);
75 printf("\n");
77 rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
78 printf("rv = %d\n", rv);
79 PR_ExplodeTime(ct, PR_GMTParameters, &et);
80 PrintExplodedTime(&et);
81 printf("\n");
83 return 0;
84 }