forked from moment/moment-timezone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utc.js
52 lines (37 loc) · 1.83 KB
/
utc.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"use strict";
var moment = require("../../");
var helpers = require("../helpers/helpers");
exports.utc = {
utc : function (test) {
moment.tz.add([
"TestUTC/Pacific|PST|80|0|",
"TestUTC/Eastern|EST|50|0|"
]);
var m = moment("2014-07-10 12:00:00+00:00"),
localFormat = m.format(),
localOffset = helpers.getUTCOffset(m);
m.tz("TestUTC/Pacific");
test.equal(helpers.getUTCOffset(m), -480, "Should change the offset when using moment.fn.tz");
test.equal(m.format(), "2014-07-10T04:00:00-08:00", "Should change the offset when using moment.fn.tz");
m.utc();
moment.updateOffset(m);
test.equal(helpers.getUTCOffset(m), 0, "Should set the offset to +00:00 when using moment.fn.utc");
test.equal(m.format(), "2014-07-10T12:00:00Z", "Should change the offset when using moment.fn.utc");
m.tz("TestUTC/Eastern");
test.equal(helpers.getUTCOffset(m), -300, "Should change the offset when using moment.fn.tz");
test.equal(m.format(), "2014-07-10T07:00:00-05:00", "Should change the offset when using moment.fn.tz");
m.utc();
moment.updateOffset(m);
test.equal(helpers.getUTCOffset(m), 0, "Should set the offset to +00:00 when using moment.fn.utc");
test.equal(m.format(), "2014-07-10T12:00:00Z", "Should change the offset when using moment.fn.utc");
m.local();
moment.updateOffset(m);
test.equal(helpers.getUTCOffset(m), localOffset, "Should reset the offset to local time when using moment.fn.local");
test.equal(m.format(), localFormat, "Should reset the offset to local time when using moment.fn.local");
m = moment('2017-01-01T00:00:00');
var utcWallTimeFormat = m.clone().utcOffset('-05:00', true).format();
m.tz('America/New_York', true);
test.equal(m.format(), utcWallTimeFormat, "Should change the offset while keeping wall time when passing an optional parameter to moment.fn.tz");
test.done();
}
};