1
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Mozilla Public License Version
6
* 1.1 (the "License"); you may not use this file except in compliance with
7
* the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/MPL/
10
* Software distributed under the License is distributed on an "AS IS" basis,
11
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
* for the specific language governing rights and limitations under the
15
* The Original Code is the Netscape Portable Runtime (NSPR).
17
* The Initial Developer of the Original Code is
18
* Netscape Communications Corporation.
19
* Portions created by the Initial Developer are Copyright (C) 1998-2000
20
* the Initial Developer. All Rights Reserved.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the MPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the MPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
39
* This test program should eventually become a full-blown test for
40
* PR_ParseTimeString. Right now it just verifies that PR_ParseTimeString
41
* doesn't crash on an out-of-range time string (bug 480740).
51
PRBool debug_mode = PR_TRUE;
53
static char *dayOfWeek[] =
54
{ "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" };
55
static char *month[] =
56
{ "Jan", "Feb", "Mar", "Apr", "May", "Jun",
57
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" };
59
static void PrintExplodedTime(const PRExplodedTime *et) {
61
PRInt32 hourOffset, minOffset;
64
/* Print day of the week, month, day, hour, minute, and second */
65
if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ",
66
dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday,
67
et->tm_hour, et->tm_min, et->tm_sec);
70
totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset;
71
if (totalOffset == 0) {
72
if (debug_mode) printf("UTC ");
75
if (totalOffset < 0) {
76
totalOffset = -totalOffset;
79
hourOffset = totalOffset / 3600;
80
minOffset = (totalOffset % 3600) / 60;
82
printf("%s%02ld%02ld ", sign, hourOffset, minOffset);
86
if (debug_mode) printf("%hd", et->tm_year);
89
int main(int argc, char **argv)
94
char *sp1 = "Sat, 1 Jan 3001 00:00:00"; /* no time zone */
95
char *sp2 = "Fri, 31 Dec 3000 23:59:60"; /* no time zone, not normalized */
98
/* Run this test in the US Pacific Time timezone. */
99
_putenv_s("TZ", "PST8PDT");
103
rv = PR_ParseTimeString(sp1, PR_FALSE, &ct);
104
printf("rv = %d\n", rv);
105
PR_ExplodeTime(ct, PR_GMTParameters, &et);
106
PrintExplodedTime(&et);
109
rv = PR_ParseTimeString(sp2, PR_FALSE, &ct);
110
printf("rv = %d\n", rv);
111
PR_ExplodeTime(ct, PR_GMTParameters, &et);
112
PrintExplodedTime(&et);