michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: /* michael@0: * This test program should eventually become a full-blown test for michael@0: * PR_ParseTimeString. Right now it just verifies that PR_ParseTimeString michael@0: * doesn't crash on an out-of-range time string (bug 480740). michael@0: */ michael@0: michael@0: #include "prtime.h" michael@0: michael@0: #include michael@0: #include michael@0: #include michael@0: #include michael@0: michael@0: PRBool debug_mode = PR_TRUE; michael@0: michael@0: static char *dayOfWeek[] = michael@0: { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" }; michael@0: static char *month[] = michael@0: { "Jan", "Feb", "Mar", "Apr", "May", "Jun", michael@0: "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" }; michael@0: michael@0: static void PrintExplodedTime(const PRExplodedTime *et) { michael@0: PRInt32 totalOffset; michael@0: PRInt32 hourOffset, minOffset; michael@0: const char *sign; michael@0: michael@0: /* Print day of the week, month, day, hour, minute, and second */ michael@0: if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ", michael@0: dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday, michael@0: et->tm_hour, et->tm_min, et->tm_sec); michael@0: michael@0: /* Print time zone */ michael@0: totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset; michael@0: if (totalOffset == 0) { michael@0: if (debug_mode) printf("UTC "); michael@0: } else { michael@0: sign = "+"; michael@0: if (totalOffset < 0) { michael@0: totalOffset = -totalOffset; michael@0: sign = "-"; michael@0: } michael@0: hourOffset = totalOffset / 3600; michael@0: minOffset = (totalOffset % 3600) / 60; michael@0: if (debug_mode) michael@0: printf("%s%02ld%02ld ", sign, hourOffset, minOffset); michael@0: } michael@0: michael@0: /* Print year */ michael@0: if (debug_mode) printf("%hd", et->tm_year); michael@0: } michael@0: michael@0: int main(int argc, char **argv) michael@0: { michael@0: PRTime ct; michael@0: PRExplodedTime et; michael@0: PRStatus rv; michael@0: char *sp1 = "Sat, 1 Jan 3001 00:00:00"; /* no time zone */ michael@0: char *sp2 = "Fri, 31 Dec 3000 23:59:60"; /* no time zone, not normalized */ michael@0: michael@0: #if _MSC_VER >= 1400 && !defined(WINCE) michael@0: /* Run this test in the US Pacific Time timezone. */ michael@0: _putenv_s("TZ", "PST8PDT"); michael@0: _tzset(); michael@0: #endif michael@0: michael@0: rv = PR_ParseTimeString(sp1, PR_FALSE, &ct); michael@0: printf("rv = %d\n", rv); michael@0: PR_ExplodeTime(ct, PR_GMTParameters, &et); michael@0: PrintExplodedTime(&et); michael@0: printf("\n"); michael@0: michael@0: rv = PR_ParseTimeString(sp2, PR_FALSE, &ct); michael@0: printf("rv = %d\n", rv); michael@0: PR_ExplodeTime(ct, PR_GMTParameters, &et); michael@0: PrintExplodedTime(&et); michael@0: printf("\n"); michael@0: michael@0: return 0; michael@0: }