| 1 |
"use strict"; |
| 2 |
|
| 3 |
var moment = require("../../index"); |
| 4 |
var helpers = require("../helpers/helpers"); |
| 5 |
|
| 6 |
var Los_Angeles = "America/Los_Angeles|PST PDT PWT PPT|80 70 70 70|010102301010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-261q0 1nX0 11B0 1nX0 SgN0 8x10 iy0 5Wp0 1Vb0 3dB0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 s10 1Vz0 LB0 1BX0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0"; |
| 7 |
var New_York = "America/New_York|EST EDT EWT EPT|50 40 40 40|01010101010101010101010101010101010101010101010102301010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010101010|-261t0 1nX0 11B0 1nX0 11B0 1qL0 1a10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 RB0 8x40 iv0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1qN0 WL0 1qN0 11z0 1o10 11z0 1o10 11z0 1o10 11z0 1o10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1cN0 1cL0 1cN0 1cL0 s10 1Vz0 LB0 1BX0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 1cN0 1fz0 1a10 1fz0 1cN0 1cL0 1cN0 1cL0 1cN0 1cL0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 14p0 1lb0 14p0 1lb0 14p0 1nX0 11B0 1nX0 11B0 1nX0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Rd0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0 Op0 1zb0"; |
| 8 |
|
| 9 |
var moveAmbiguousForward, moveInvalidForward; |
| 10 |
|
| 11 |
exports.parse = { |
| 12 |
setUp : function (done) { |
| 13 |
moment.tz.add([Los_Angeles, New_York]); |
| 14 |
|
| 15 |
moveAmbiguousForward = moment.tz.moveAmbiguousForward; |
| 16 |
moveInvalidForward = moment.tz.moveInvalidForward; |
| 17 |
done(); |
| 18 |
}, |
| 19 |
|
| 20 |
tearDown : function (done) { |
| 21 |
moment.tz.moveAmbiguousForward = moveAmbiguousForward; |
| 22 |
moment.tz.moveInvalidForward = moveInvalidForward; |
| 23 |
moment.tz.setDefault(null); |
| 24 |
done(); |
| 25 |
}, |
| 26 |
|
| 27 |
"default states" : function (t) { |
| 28 |
t.ok(moment.tz.moveInvalidForward, "Should default to moving invalid input forward"); |
| 29 |
t.ok(!moment.tz.moveAmbiguousForward, "Should default to moving ambiguous input backward"); |
| 30 |
|
| 31 |
t.done(); |
| 32 |
}, |
| 33 |
|
| 34 |
"invalid input - moveInvalidForward = false - Los Angeles" : function (t) { |
| 35 |
moment.tz.moveInvalidForward = false; |
| 36 |
|
| 37 |
|
| 38 |
var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/Los_Angeles"), |
| 39 |
atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/Los_Angeles"), |
| 40 |
atEnd = moment.tz([2012, 2, 11, 2, 59, 59], "America/Los_Angeles"), |
| 41 |
after = moment.tz([2012, 2, 11, 3, 0, 0], "America/Los_Angeles"); |
| 42 |
|
| 43 |
t.equal( before.format("HH mm ss Z"), "01 59 59 -08:00", "Before the lost hour, the time should match the input time"); |
| 44 |
t.equal(atStart.format("HH mm ss Z"), "01 00 00 -08:00", "During the lost hour, the time should roll back to the previous time"); |
| 45 |
t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the lost hour, the time should roll back to the previous time"); |
| 46 |
t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); |
| 47 |
|
| 48 |
t.equal(helpers.getUTCOffset(before), -480, "Before the lost hour, the offset should match the non-dst offset"); |
| 49 |
t.equal(helpers.getUTCOffset(atStart), -480, "During the lost hour, the offset should match the non-dst offset"); |
| 50 |
t.equal(helpers.getUTCOffset(atEnd), -480, "During the lost hour, the offset should match the non-dst offset"); |
| 51 |
t.equal(helpers.getUTCOffset(after), -420, "After the lost hour, the offset should match the dst offset"); |
| 52 |
|
| 53 |
t.done(); |
| 54 |
}, |
| 55 |
|
| 56 |
"invalid input - moveInvalidForward = false - New York" : function (t) { |
| 57 |
moment.tz.moveInvalidForward = false; |
| 58 |
|
| 59 |
|
| 60 |
var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/New_York"), |
| 61 |
atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/New_York"), |
| 62 |
atEnd = moment.tz([2012, 2, 11, 2, 59, 59], "America/New_York"), |
| 63 |
after = moment.tz([2012, 2, 11, 3, 0, 0], "America/New_York"); |
| 64 |
|
| 65 |
t.equal( before.format("HH mm ss Z"), "01 59 59 -05:00", "Before the lost hour, the time should match the input time"); |
| 66 |
t.equal(atStart.format("HH mm ss Z"), "01 00 00 -05:00", "During the lost hour, the time should roll back to the previous time"); |
| 67 |
t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the lost hour, the time should roll back to the previous time"); |
| 68 |
t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); |
| 69 |
|
| 70 |
t.equal(helpers.getUTCOffset(before), -300, "Before the lost hour, the offset should match the non-dst offset"); |
| 71 |
t.equal(helpers.getUTCOffset(atStart), -300, "During the lost hour, the offset should match the non-dst offset"); |
| 72 |
t.equal(helpers.getUTCOffset(atEnd), -300, "During the lost hour, the offset should match the non-dst offset"); |
| 73 |
t.equal(helpers.getUTCOffset(after), -240, "After the lost hour, the offset should match the dst offset"); |
| 74 |
|
| 75 |
t.done(); |
| 76 |
}, |
| 77 |
|
| 78 |
"invalid input - moveInvalidForward = true - Los Angeles" : function (t) { |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/Los_Angeles"), |
| 83 |
atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/Los_Angeles"), |
| 84 |
atEnd = moment.tz([2012, 2, 11, 2, 59, 59], "America/Los_Angeles"), |
| 85 |
after = moment.tz([2012, 2, 11, 3, 0, 0], "America/Los_Angeles"); |
| 86 |
|
| 87 |
t.equal( before.format("HH mm ss Z"), "01 59 59 -08:00", "Before the lost hour, the time should match the input time"); |
| 88 |
t.equal(atStart.format("HH mm ss Z"), "03 00 00 -07:00", "During the lost hour, the time should roll forward to the previous time"); |
| 89 |
t.equal( atEnd.format("HH mm ss Z"), "03 59 59 -07:00", "During the lost hour, the time should roll forward to the previous time"); |
| 90 |
t.equal( after.format("HH mm ss Z"), "03 00 00 -07:00", "After the lost hour, the time should match the input time"); |
| 91 |
|
| 92 |
t.equal(helpers.getUTCOffset(before), -480, "Before the lost hour, the offset should match the non-dst offset"); |
| 93 |
t.equal(helpers.getUTCOffset(atStart), -420, "During the lost hour, the offset should match the dst offset"); |
| 94 |
t.equal(helpers.getUTCOffset(atEnd), -420, "During the lost hour, the offset should match the dst offset"); |
| 95 |
t.equal(helpers.getUTCOffset(after), -420, "After the lost hour, the offset should match the dst offset"); |
| 96 |
|
| 97 |
t.done(); |
| 98 |
}, |
| 99 |
|
| 100 |
"invalid input - moveInvalidForward = true - New York" : function (t) { |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
var before = moment.tz([2012, 2, 11, 1, 59, 59], "America/New_York"), |
| 105 |
atStart = moment.tz([2012, 2, 11, 2, 0, 0], "America/New_York"), |
| 106 |
atEnd = moment.tz([2012, 2, 11, 2, 59, 59], "America/New_York"), |
| 107 |
after = moment.tz([2012, 2, 11, 3, 0, 0], "America/New_York"); |
| 108 |
|
| 109 |
t.equal( before.format("HH mm ss Z"), "01 59 59 -05:00", "Before the lost hour, the time should match the input time"); |
| 110 |
t.equal(atStart.format("HH mm ss Z"), "03 00 00 -04:00", "During the lost hour, the time should roll forward to the previous time"); |
| 111 |
t.equal( atEnd.format("HH mm ss Z"), "03 59 59 -04:00", "During the lost hour, the time should roll forward to the previous time"); |
| 112 |
t.equal( after.format("HH mm ss Z"), "03 00 00 -04:00", "After the lost hour, the time should match the input time"); |
| 113 |
|
| 114 |
t.equal(helpers.getUTCOffset(before), -300, "Before the lost hour, the offset should match the non-dst offset"); |
| 115 |
t.equal(helpers.getUTCOffset(atStart), -240, "During the lost hour, the offset should match the dst offset"); |
| 116 |
t.equal(helpers.getUTCOffset(atEnd), -240, "During the lost hour, the offset should match the dst offset"); |
| 117 |
t.equal(helpers.getUTCOffset(after), -240, "After the lost hour, the offset should match the dst offset"); |
| 118 |
|
| 119 |
t.done(); |
| 120 |
}, |
| 121 |
|
| 122 |
"ambiguous input - moveAmbiguousForward = false - Los Angeles" : function (t) { |
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/Los_Angeles"), |
| 127 |
atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/Los_Angeles"), |
| 128 |
atEnd = moment.tz([2012, 10, 4, 1, 59, 59], "America/Los_Angeles"), |
| 129 |
after = moment.tz([2012, 10, 4, 2, 0, 0], "America/Los_Angeles"); |
| 130 |
|
| 131 |
t.equal( before.format("HH mm ss Z"), "00 59 59 -07:00", "Before the duplicated hour, the time should match the input time"); |
| 132 |
t.equal(atStart.format("HH mm ss Z"), "01 00 00 -07:00", "During the duplicated hour, the time should match the earlier input time"); |
| 133 |
t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -07:00", "During the duplicated hour, the time should match the earlier input time"); |
| 134 |
t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); |
| 135 |
|
| 136 |
t.equal(helpers.getUTCOffset(before), -420, "Before the duplicated hour, the offset should match the dst offset"); |
| 137 |
t.equal(helpers.getUTCOffset(atStart), -420, "During the duplicated hour, the offset should match the dst offset"); |
| 138 |
t.equal(helpers.getUTCOffset(atEnd), -420, "During the duplicated hour, the offset should match the dst offset"); |
| 139 |
t.equal(helpers.getUTCOffset(after), -480, "After the duplicated hour, the offset should match the non-dst offset"); |
| 140 |
|
| 141 |
t.done(); |
| 142 |
}, |
| 143 |
|
| 144 |
"ambiguous input - moveAmbiguousForward = false - New York" : function (t) { |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/New_York"), |
| 149 |
atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/New_York"), |
| 150 |
atEnd = moment.tz([2012, 10, 4, 1, 59, 59], "America/New_York"), |
| 151 |
after = moment.tz([2012, 10, 4, 2, 0, 0], "America/New_York"); |
| 152 |
|
| 153 |
t.equal( before.format("HH mm ss Z"), "00 59 59 -04:00", "Before the duplicated hour, the time should match the input time"); |
| 154 |
t.equal(atStart.format("HH mm ss Z"), "01 00 00 -04:00", "During the duplicated hour, the time should match the earlier input time"); |
| 155 |
t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -04:00", "During the duplicated hour, the time should match the earlier input time"); |
| 156 |
t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); |
| 157 |
|
| 158 |
t.equal(helpers.getUTCOffset(before), -240, "Before the duplicated hour, the offset should match the dst offset"); |
| 159 |
t.equal(helpers.getUTCOffset(atStart), -240, "During the duplicated hour, the offset should match the dst offset"); |
| 160 |
t.equal(helpers.getUTCOffset(atEnd), -240, "During the duplicated hour, the offset should match the dst offset"); |
| 161 |
t.equal(helpers.getUTCOffset(after), -300, "After the duplicated hour, the offset should match the non-dst offset"); |
| 162 |
|
| 163 |
t.done(); |
| 164 |
}, |
| 165 |
|
| 166 |
"ambiguous input - moveAmbiguousForward = true - Los Angeles" : function (t) { |
| 167 |
moment.tz.moveAmbiguousForward = true; |
| 168 |
|
| 169 |
|
| 170 |
var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/Los_Angeles"), |
| 171 |
atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/Los_Angeles"), |
| 172 |
atEnd = moment.tz([2012, 10, 4, 1, 59, 59], "America/Los_Angeles"), |
| 173 |
after = moment.tz([2012, 10, 4, 2, 0, 0], "America/Los_Angeles"); |
| 174 |
|
| 175 |
t.equal( before.format("HH mm ss Z"), "00 59 59 -07:00", "Before the duplicated hour, the time should match the input time"); |
| 176 |
t.equal(atStart.format("HH mm ss Z"), "01 00 00 -08:00", "During the duplicated hour, the time should match the later input time"); |
| 177 |
t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -08:00", "During the duplicated hour, the time should match the later input time"); |
| 178 |
t.equal( after.format("HH mm ss Z"), "02 00 00 -08:00", "After the duplicated hour, the time should match the input time"); |
| 179 |
|
| 180 |
t.equal(helpers.getUTCOffset(before), -420, "Before the duplicated hour, the offset should match the dst offset"); |
| 181 |
t.equal(helpers.getUTCOffset(atStart), -480, "During the duplicated hour, the offset should match the non-dst offset"); |
| 182 |
t.equal(helpers.getUTCOffset(atEnd), -480, "During the duplicated hour, the offset should match the non-dst offset"); |
| 183 |
t.equal(helpers.getUTCOffset(after), -480, "After the duplicated hour, the offset should match the non-dst offset"); |
| 184 |
|
| 185 |
t.done(); |
| 186 |
}, |
| 187 |
|
| 188 |
"ambiguous input - moveAmbiguousForward = true - New York" : function (t) { |
| 189 |
moment.tz.moveAmbiguousForward = true; |
| 190 |
|
| 191 |
|
| 192 |
var before = moment.tz([2012, 10, 4, 0, 59, 59], "America/New_York"), |
| 193 |
atStart = moment.tz([2012, 10, 4, 1, 0, 0], "America/New_York"), |
| 194 |
atEnd = moment.tz([2012, 10, 4, 1, 59, 59], "America/New_York"), |
| 195 |
after = moment.tz([2012, 10, 4, 2, 0, 0], "America/New_York"); |
| 196 |
|
| 197 |
t.equal( before.format("HH mm ss Z"), "00 59 59 -04:00", "Before the duplicated hour, the time should match the input time"); |
| 198 |
t.equal(atStart.format("HH mm ss Z"), "01 00 00 -05:00", "During the duplicated hour, the time should match the later input time"); |
| 199 |
t.equal( atEnd.format("HH mm ss Z"), "01 59 59 -05:00", "During the duplicated hour, the time should match the later input time"); |
| 200 |
t.equal( after.format("HH mm ss Z"), "02 00 00 -05:00", "After the duplicated hour, the time should match the input time"); |
| 201 |
|
| 202 |
t.equal(helpers.getUTCOffset(before), -240, "Before the duplicated hour, the offset should match the dst offset"); |
| 203 |
t.equal(helpers.getUTCOffset(atStart), -300, "During the duplicated hour, the offset should match the non-dst offset"); |
| 204 |
t.equal(helpers.getUTCOffset(atEnd), -300, "During the duplicated hour, the offset should match the non-dst offset"); |
| 205 |
t.equal(helpers.getUTCOffset(after), -300, "After the duplicated hour, the offset should match the non-dst offset"); |
| 206 |
|
| 207 |
t.done(); |
| 208 |
}, |
| 209 |
|
| 210 |
"check needsOffset in moment.tz (America/Los_Angeles)" : function (t) { |
| 211 |
var name = "America/Los_Angeles", |
| 212 |
tests = [ |
| 213 |
[moment.tz([2012, 5, 1], name), "2012-06-01 00:00:00 -07:00", "[2012, 5, 1]"], |
| 214 |
[moment.tz("2012-06-01", name), "2012-06-01 00:00:00 -07:00", "2012-06-01"], |
| 215 |
[moment.tz("2012-06-01 07:00:00+00:00", name), "2012-06-01 00:00:00 -07:00", "2012-06-01 00:00:00+00:00"], |
| 216 |
[moment.tz(1338534000000, name), "2012-06-01 00:00:00 -07:00", "1338534000000"], |
| 217 |
[moment.tz(new Date(1338534000000), name), "2012-06-01 00:00:00 -07:00", "new Date(1338534000000)"], |
| 218 |
[moment.tz({y : 2012, M : 5, d : 1}, name), "2012-06-01 00:00:00 -07:00", "{y : 2012, M : 5, d : 1}"], |
| 219 |
[moment.tz(moment.utc([2012, 5, 1, 7]), name), "2012-06-01 00:00:00 -07:00", "moment.utc([2012, 5, 1, 7])"] |
| 220 |
], i, actual, message, expected; |
| 221 |
|
| 222 |
for (i = 0; i < tests.length; i++) { |
| 223 |
actual = tests[i][0].format('YYYY-MM-DD HH:mm:ss Z'); |
| 224 |
expected = tests[i][1]; |
| 225 |
message = tests[i][2]; |
| 226 |
t.equal(actual, expected, "Parsing " + message + " in America/Los_Angeles should equal " + expected); |
| 227 |
} |
| 228 |
|
| 229 |
t.done(); |
| 230 |
}, |
| 231 |
|
| 232 |
"check needsOffset in moment.tz (America/New_York)" : function (t) { |
| 233 |
var name = "America/New_York", |
| 234 |
tests = [ |
| 235 |
[moment.tz([2012, 5, 1], name), "2012-06-01 00:00:00 -04:00", "[2012, 5, 1]"], |
| 236 |
[moment.tz("2012-06-01", name), "2012-06-01 00:00:00 -04:00", "2012-06-01"], |
| 237 |
[moment.tz("2012-06-01 04:00:00+00:00", name), "2012-06-01 00:00:00 -04:00", "2012-06-01 00:00:00+00:00"], |
| 238 |
[moment.tz(1338523200000, name), "2012-06-01 00:00:00 -04:00", "1338534000000"], |
| 239 |
[moment.tz(new Date(1338523200000), name), "2012-06-01 00:00:00 -04:00", "new Date(1338534000000)"], |
| 240 |
[moment.tz({y : 2012, M : 5, d : 1}, name), "2012-06-01 00:00:00 -04:00", "{y : 2012, M : 5, d : 1}"], |
| 241 |
[moment.tz(moment.utc([2012, 5, 1, 4]), name), "2012-06-01 00:00:00 -04:00", "moment.utc([2012, 5, 1, 4])"] |
| 242 |
], i, actual, message, expected; |
| 243 |
|
| 244 |
for (i = 0; i < tests.length; i++) { |
| 245 |
actual = tests[i][0].format('YYYY-MM-DD HH:mm:ss Z'); |
| 246 |
expected = tests[i][1]; |
| 247 |
message = tests[i][2]; |
| 248 |
t.equal(actual, expected, "Parsing " + message + " in America/New_York should equal " + expected); |
| 249 |
} |
| 250 |
|
| 251 |
t.done(); |
| 252 |
}, |
| 253 |
|
| 254 |
"check needsOffset in moment.tz with timestamp formats" : function (t) { |
| 255 |
var tests = [ |
| 256 |
["1338534000000", "x", "America/New_York", 1338534000000, "2012-06-01T03:00:00-04:00"], |
| 257 |
["1338534000.000", "X", "America/New_York", 1338534000000, "2012-06-01T03:00:00-04:00"], |
| 258 |
["1338534000000", "x", "America/Los_Angeles", 1338534000000, "2012-06-01T00:00:00-07:00"], |
| 259 |
["1338534000.000", "X", "America/Los_Angeles", 1338534000000, "2012-06-01T00:00:00-07:00"] |
| 260 |
], i, parsed, input, format, timezone, expectedValue, expectedFormat, actualValue, actualFormat; |
| 261 |
|
| 262 |
for (i = 0; i < tests.length; i++) { |
| 263 |
input = tests[i][0]; |
| 264 |
format = tests[i][1]; |
| 265 |
timezone = tests[i][2]; |
| 266 |
expectedValue = tests[i][3]; |
| 267 |
expectedFormat = tests[i][4]; |
| 268 |
parsed = moment.tz(input, format, true, timezone); |
| 269 |
t.equal(parsed.valueOf(), expectedValue, "Parsing " + input + " with format " + format + " should have value " + expectedValue); |
| 270 |
t.equal(parsed.format(), expectedFormat, "Parsing " + input + " with format " + format + " should equal " + expectedFormat); |
| 271 |
} |
| 272 |
|
| 273 |
t.done(); |
| 274 |
}, |
| 275 |
|
| 276 |
"parse in default zone" : function (t) { |
| 277 |
moment.tz.setDefault("America/New_York"); |
| 278 |
|
| 279 |
var tests = [ |
| 280 |
[moment([2012, 5, 1]), "2012-06-01 00:00:00 -04:00", "[2012, 5, 1]"], |
| 281 |
[moment("2012-06-01"), "2012-06-01 00:00:00 -04:00", "2012-06-01"], |
| 282 |
[moment("2012-06-01 04:00:00+00:00"), "2012-06-01 00:00:00 -04:00", "2012-06-01 00:00:00+00:00"], |
| 283 |
[moment(1338523200000), "2012-06-01 00:00:00 -04:00", "1338534000000"], |
| 284 |
[moment(new Date(1338523200000)), "2012-06-01 00:00:00 -04:00", "new Date(1338534000000)"], |
| 285 |
[moment({y : 2012, M : 5, d : 1}), "2012-06-01 00:00:00 -04:00", "{y : 2012, M : 5, d : 1}"] |
| 286 |
], i, actual, message, expected; |
| 287 |
|
| 288 |
for (i = 0; i < tests.length; i++) { |
| 289 |
actual = tests[i][0].format('YYYY-MM-DD HH:mm:ss Z'); |
| 290 |
expected = tests[i][1]; |
| 291 |
message = tests[i][2]; |
| 292 |
t.equal(actual, expected, "Parsing " + message + " in America/New_York should equal " + expected); |
| 293 |
} |
| 294 |
|
| 295 |
t.done(); |
| 296 |
} |
| 297 |
|
| 298 |
}; |