Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
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 | var BUGNUMBER = 430930; |
michael@0 | 8 | |
michael@0 | 9 | |
michael@0 | 10 | //----------------------------------------------------------------------------- |
michael@0 | 11 | test(); |
michael@0 | 12 | //----------------------------------------------------------------------------- |
michael@0 | 13 | |
michael@0 | 14 | function iso(d) |
michael@0 | 15 | { |
michael@0 | 16 | return new Date(d).toISOString(); |
michael@0 | 17 | } |
michael@0 | 18 | |
michael@0 | 19 | function check(s, millis){ |
michael@0 | 20 | description = "Date.parse('"+s+"') == '"+iso(millis)+"'"; |
michael@0 | 21 | expected = millis; |
michael@0 | 22 | actual = Date.parse(s); |
michael@0 | 23 | reportCompare(expected, actual, description); |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | function checkInvalid(s) |
michael@0 | 27 | { |
michael@0 | 28 | description = "Date.parse('"+s+"') produces invalid date"; |
michael@0 | 29 | expected = NaN; |
michael@0 | 30 | actual = Date.parse(s); |
michael@0 | 31 | reportCompare(expected, actual, description); |
michael@0 | 32 | } |
michael@0 | 33 | |
michael@0 | 34 | function dd(year, month, day, hour, minute, second, millis){ |
michael@0 | 35 | return Date.UTC(year, month-1, day, hour, minute, second, millis); |
michael@0 | 36 | } |
michael@0 | 37 | |
michael@0 | 38 | function TZAtDate(d){ |
michael@0 | 39 | return d.getTimezoneOffset() * 60000; |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function TZInMonth(month){ |
michael@0 | 43 | return TZAtDate(new Date(dd(2009,month,1,0,0,0,0))); |
michael@0 | 44 | } |
michael@0 | 45 | |
michael@0 | 46 | function test() |
michael@0 | 47 | { |
michael@0 | 48 | enterFunc ('test'); |
michael@0 | 49 | printBugNumber(BUGNUMBER); |
michael@0 | 50 | |
michael@0 | 51 | JanTZ = TZInMonth(1); |
michael@0 | 52 | JulTZ = TZInMonth(7); |
michael@0 | 53 | CurrTZ = TZAtDate(new Date()); |
michael@0 | 54 | |
michael@0 | 55 | // formats with explicit timezone |
michael@0 | 56 | check("2009-07-23T19:53:21.001+12:00", dd(2009,7,23,7,53,21,1)); |
michael@0 | 57 | check("2009-07-23T19:53:21+12:00", dd(2009,7,23,7,53,21,0)); |
michael@0 | 58 | check("2009-07-23T19:53+12:00", dd(2009,7,23,7,53,0,0)); |
michael@0 | 59 | |
michael@0 | 60 | check("2009-07T19:53:21.001+12:00", dd(2009,7,1,7,53,21,1)); |
michael@0 | 61 | check("2009-07T19:53:21+12:00", dd(2009,7,1,7,53,21,0)); |
michael@0 | 62 | check("2009-07T19:53+12:00", dd(2009,7,1,7,53,0,0)); |
michael@0 | 63 | |
michael@0 | 64 | check("2009T19:53:21.001+12:00", dd(2009,1,1,7,53,21,1)); |
michael@0 | 65 | check("2009T19:53:21+12:00", dd(2009,1,1,7,53,21,0)); |
michael@0 | 66 | check("2009T19:53+12:00", dd(2009,1,1,7,53,0,0)); |
michael@0 | 67 | |
michael@0 | 68 | check("T19:53:21.001+12:00", dd(1970,1,1,7,53,21,1)); |
michael@0 | 69 | check("T19:53:21+12:00", dd(1970,1,1,7,53,21,0)); |
michael@0 | 70 | check("T19:53+12:00", dd(1970,1,1,7,53,0,0)); |
michael@0 | 71 | |
michael@0 | 72 | // formats without timezone uses the timezone as at that date |
michael@0 | 73 | check("2009-07-23T19:53:21.001", dd(2009,7,23,19,53,21,1)+JulTZ); |
michael@0 | 74 | check("2009-07-23T19:53:21", dd(2009,7,23,19,53,21,0)+JulTZ); |
michael@0 | 75 | check("2009-07-23T19:53", dd(2009,7,23,19,53,0,0)+JulTZ); |
michael@0 | 76 | |
michael@0 | 77 | check("2009-07T19:53:21.001", dd(2009,7,1,19,53,21,1)+JulTZ); |
michael@0 | 78 | check("2009-07T19:53:21", dd(2009,7,1,19,53,21,0)+JulTZ); |
michael@0 | 79 | check("2009-07T19:53", dd(2009,7,1,19,53,0,0)+JulTZ); |
michael@0 | 80 | |
michael@0 | 81 | check("2009T19:53:21.001", dd(2009,1,1,19,53,21,1)+JanTZ); |
michael@0 | 82 | check("2009T19:53:21", dd(2009,1,1,19,53,21,0)+JanTZ); |
michael@0 | 83 | check("2009T19:53", dd(2009,1,1,19,53,0,0)+JanTZ); |
michael@0 | 84 | |
michael@0 | 85 | check("T19:53:21.001", dd(1970,1,1,19,53,21,1)+JanTZ); |
michael@0 | 86 | check("T19:53:21", dd(1970,1,1,19,53,21,0)+JanTZ); |
michael@0 | 87 | check("T19:53", dd(1970,1,1,19,53,0,0)+JanTZ); |
michael@0 | 88 | |
michael@0 | 89 | // with no time at all assume UTC |
michael@0 | 90 | check("2009-07-23", dd(2009,7,23,0,0,0,0)); |
michael@0 | 91 | check("2009-07", dd(2009,7,1,0,0,0,0)); |
michael@0 | 92 | check("2009", dd(2009,1,1,0,0,0,0)); |
michael@0 | 93 | |
michael@0 | 94 | // one field too big |
michael@0 | 95 | checkInvalid("2009-13-23T19:53:21.001+12:00"); |
michael@0 | 96 | checkInvalid("2009-07-32T19:53:21.001+12:00"); |
michael@0 | 97 | checkInvalid("2009-07-23T25:53:21.001+12:00"); |
michael@0 | 98 | checkInvalid("2009-07-23T19:60:21.001+12:00"); |
michael@0 | 99 | checkInvalid("2009-07-23T19:53:60.001+12:00"); |
michael@0 | 100 | checkInvalid("2009-07-23T19:53:21.001+24:00"); |
michael@0 | 101 | checkInvalid("2009-07-23T19:53:21.001+12:60"); |
michael@0 | 102 | |
michael@0 | 103 | // other month ends |
michael@0 | 104 | check("2009-06-30T19:53:21.001+12:00", dd(2009,6,30,7,53,21,1)); |
michael@0 | 105 | checkInvalid("2009-06-31T19:53:21.001+12:00"); |
michael@0 | 106 | check("2009-02-28T19:53:21.001+12:00", dd(2009,2,28,7,53,21,1)); |
michael@0 | 107 | checkInvalid("2009-02-29T19:53:21.001+12:00"); |
michael@0 | 108 | check("2008-02-29T19:53:21.001+12:00", dd(2008,2,29,7,53,21,1)); |
michael@0 | 109 | checkInvalid("2008-02-30T19:53:21.001+12:00"); |
michael@0 | 110 | |
michael@0 | 111 | // limits of representation |
michael@0 | 112 | checkInvalid("-271821-04-19T23:59:59.999Z"); |
michael@0 | 113 | check("-271821-04-20", -8.64e15); |
michael@0 | 114 | check("+275760-09-13", 8.64e15); |
michael@0 | 115 | checkInvalid("+275760-09-13T00:00:00.001Z"); |
michael@0 | 116 | |
michael@0 | 117 | check("-269845-07-23T19:53:21.001+12:00", dd(-269845,7,23,7,53,21,1)); |
michael@0 | 118 | check("+273785-07-23T19:53:21.001+12:00", dd(273785,7,23,7,53,21,1)); |
michael@0 | 119 | |
michael@0 | 120 | // explicit UTC |
michael@0 | 121 | check("2009-07-23T19:53:21.001Z", dd(2009,7,23,19,53,21,1)); |
michael@0 | 122 | check("+002009-07-23T19:53:21.001Z", dd(2009,7,23,19,53,21,1)); |
michael@0 | 123 | |
michael@0 | 124 | // different timezones |
michael@0 | 125 | check("2009-07-23T19:53:21.001+12:00", dd(2009,7,23,7,53,21,1)); |
michael@0 | 126 | check("2009-07-23T00:53:21.001-07:00", dd(2009,7,23,7,53,21,1)); |
michael@0 | 127 | |
michael@0 | 128 | // 00:00 and 24:00 |
michael@0 | 129 | check("2009-07-23T00:00:00.000-07:00", dd(2009,7,23,7,0,0,0)); |
michael@0 | 130 | check("2009-07-23T24:00:00.000-07:00", dd(2009,7,24,7,0,0,0)); |
michael@0 | 131 | |
michael@0 | 132 | exitFunc ('test'); |
michael@0 | 133 | } |