Wed, 31 Dec 2014 06:55:50 +0100
Added tag UPSTREAM_283F7C6 for changeset ca08bd8f51b2
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * This test program should eventually become a full-blown test for |
michael@0 | 8 | * PR_ParseTimeString. Right now it just verifies that PR_ParseTimeString |
michael@0 | 9 | * doesn't crash on an out-of-range time string (bug 480740). |
michael@0 | 10 | */ |
michael@0 | 11 | |
michael@0 | 12 | #include "prtime.h" |
michael@0 | 13 | |
michael@0 | 14 | #include <time.h> |
michael@0 | 15 | #include <stdio.h> |
michael@0 | 16 | #include <stdlib.h> |
michael@0 | 17 | #include <string.h> |
michael@0 | 18 | |
michael@0 | 19 | PRBool debug_mode = PR_TRUE; |
michael@0 | 20 | |
michael@0 | 21 | static char *dayOfWeek[] = |
michael@0 | 22 | { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "???" }; |
michael@0 | 23 | static char *month[] = |
michael@0 | 24 | { "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
michael@0 | 25 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "???" }; |
michael@0 | 26 | |
michael@0 | 27 | static void PrintExplodedTime(const PRExplodedTime *et) { |
michael@0 | 28 | PRInt32 totalOffset; |
michael@0 | 29 | PRInt32 hourOffset, minOffset; |
michael@0 | 30 | const char *sign; |
michael@0 | 31 | |
michael@0 | 32 | /* Print day of the week, month, day, hour, minute, and second */ |
michael@0 | 33 | if (debug_mode) printf("%s %s %ld %02ld:%02ld:%02ld ", |
michael@0 | 34 | dayOfWeek[et->tm_wday], month[et->tm_month], et->tm_mday, |
michael@0 | 35 | et->tm_hour, et->tm_min, et->tm_sec); |
michael@0 | 36 | |
michael@0 | 37 | /* Print time zone */ |
michael@0 | 38 | totalOffset = et->tm_params.tp_gmt_offset + et->tm_params.tp_dst_offset; |
michael@0 | 39 | if (totalOffset == 0) { |
michael@0 | 40 | if (debug_mode) printf("UTC "); |
michael@0 | 41 | } else { |
michael@0 | 42 | sign = "+"; |
michael@0 | 43 | if (totalOffset < 0) { |
michael@0 | 44 | totalOffset = -totalOffset; |
michael@0 | 45 | sign = "-"; |
michael@0 | 46 | } |
michael@0 | 47 | hourOffset = totalOffset / 3600; |
michael@0 | 48 | minOffset = (totalOffset % 3600) / 60; |
michael@0 | 49 | if (debug_mode) |
michael@0 | 50 | printf("%s%02ld%02ld ", sign, hourOffset, minOffset); |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | /* Print year */ |
michael@0 | 54 | if (debug_mode) printf("%hd", et->tm_year); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | int main(int argc, char **argv) |
michael@0 | 58 | { |
michael@0 | 59 | PRTime ct; |
michael@0 | 60 | PRExplodedTime et; |
michael@0 | 61 | PRStatus rv; |
michael@0 | 62 | char *sp1 = "Sat, 1 Jan 3001 00:00:00"; /* no time zone */ |
michael@0 | 63 | char *sp2 = "Fri, 31 Dec 3000 23:59:60"; /* no time zone, not normalized */ |
michael@0 | 64 | |
michael@0 | 65 | #if _MSC_VER >= 1400 && !defined(WINCE) |
michael@0 | 66 | /* Run this test in the US Pacific Time timezone. */ |
michael@0 | 67 | _putenv_s("TZ", "PST8PDT"); |
michael@0 | 68 | _tzset(); |
michael@0 | 69 | #endif |
michael@0 | 70 | |
michael@0 | 71 | rv = PR_ParseTimeString(sp1, PR_FALSE, &ct); |
michael@0 | 72 | printf("rv = %d\n", rv); |
michael@0 | 73 | PR_ExplodeTime(ct, PR_GMTParameters, &et); |
michael@0 | 74 | PrintExplodedTime(&et); |
michael@0 | 75 | printf("\n"); |
michael@0 | 76 | |
michael@0 | 77 | rv = PR_ParseTimeString(sp2, PR_FALSE, &ct); |
michael@0 | 78 | printf("rv = %d\n", rv); |
michael@0 | 79 | PR_ExplodeTime(ct, PR_GMTParameters, &et); |
michael@0 | 80 | PrintExplodedTime(&et); |
michael@0 | 81 | printf("\n"); |
michael@0 | 82 | |
michael@0 | 83 | return 0; |
michael@0 | 84 | } |