Bug 1825055 [wpt PR 39247] - Add support for allowing elements with display:contents...
[gecko.git] / nsprpub / pr / tests / parsetm.c
blob0e25ffe68d6b254ddb9e14a5c30679794c5a0320
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).
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", "???"
28 static void PrintExplodedTime(const PRExplodedTime *et) {
29 PRInt32 totalOffset;
30 PRInt32 hourOffset, minOffset;
31 const char *sign;
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);
38 /* Print time zone */
39 totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
40 if (totalOffset == 0) {
41 if (debug_mode) {
42 printf("UTC ");
44 } else {
45 sign = "+";
46 if (totalOffset < 0) {
47 totalOffset = -totalOffset;
48 sign = "-";
50 hourOffset = totalOffset / 3600;
51 minOffset = (totalOffset % 3600) / 60;
52 if (debug_mode) {
53 printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
57 /* Print year */
58 if (debug_mode) {
59 printf("%hd", et->tm_year);
63 int main(int argc, char **argv)
65 PRTime ct;
66 PRExplodedTime et;
67 PRStatus rv;
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");
74 _tzset();
75 #endif
77 rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
78 printf("rv = %d\n", rv);
79 PR_ExplodeTime(ct, PR_GMTParameters, &et);
80 PrintExplodedTime(&et);
81 printf("\n");
83 rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
84 printf("rv = %d\n", rv);
85 PR_ExplodeTime(ct, PR_GMTParameters, &et);
86 PrintExplodedTime(&et);
87 printf("\n");
89 return 0;