Debian Codegraph @

tests/moment-timezone/utc.js

raw symbols SCIP
1 "use strict";
2
3 var moment = require("../../");
4 var helpers = require("../helpers/helpers");
5
6 exports.utc = {
7 utc : function (test) {
8 moment.tz.add([
9 "TestUTC/Pacific|PST|80|0|",
10 "TestUTC/Mountain|MST|70|0|",
11 "TestUTC/Central|CST|60|0|",
12 "TestUTC/Eastern|EST|50|0|"
13 ]);
14
15 var m = moment("2014-07-10T12:00:00+00:00"),
16 localFormat = m.format(),
17 localOffset = helpers.getUTCOffset(m);
18
19 m.tz("TestUTC/Pacific");
20
21 test.equal(helpers.getUTCOffset(m), -480, "Should change the offset when using moment.fn.tz");
22 test.equal(m.format(), "2014-07-10T04:00:00-08:00", "Should change the offset when using moment.fn.tz");
23 test.equal(m.tz(), "TestUTC/Pacific", "Should set the time zone name when using moment.fn.tz");
24
25 m.utc();
26 moment.updateOffset(m);
27
28 test.equal(helpers.getUTCOffset(m), 0, "Should set the offset to +00:00 when using moment.fn.utc");
29 test.equal(m.format(), "2014-07-10T12:00:00Z", "Should change the offset when using moment.fn.utc");
30 test.equal(m.tz(), undefined, "Should clear the time zone name when using moment.fn.utc");
31
32 m.tz("TestUTC/Mountain");
33
34 test.equal(helpers.getUTCOffset(m), -420, "Should change the offset when using moment.fn.tz");
35 test.equal(m.format(), "2014-07-10T05:00:00-07:00", "Should change the offset when using moment.fn.tz");
36 test.equal(m.tz(), "TestUTC/Mountain", "Should set the time zone name when using moment.fn.tz");
37
38 m.utc();
39 moment.updateOffset(m);
40
41 test.equal(helpers.getUTCOffset(m), 0, "Should set the offset to +00:00 when using moment.fn.utc");
42 test.equal(m.format(), "2014-07-10T12:00:00Z", "Should change the offset when using moment.fn.utc");
43 test.equal(m.tz(), undefined, "Should clear the time zone name when using moment.fn.utc");
44
45 m.tz("TestUTC/Central");
46
47 test.equal(helpers.getUTCOffset(m), -360, "Should change the offset when using moment.fn.tz");
48 test.equal(m.format(), "2014-07-10T06:00:00-06:00", "Should change the offset when using moment.fn.tz");
49 test.equal(m.tz(), "TestUTC/Central", "Should set the time zone name when using moment.fn.tz");
50
51 m.local();
52 moment.updateOffset(m);
53
54 test.equal(helpers.getUTCOffset(m), localOffset, "Should reset the offset to local time when using moment.fn.local");
55 test.equal(m.format(), localFormat, "Should reset the offset to local time when using moment.fn.local");
56 test.equal(m.tz(), undefined, "Should clear the time zone name when using moment.fn.local");
57
58 m.tz("TestUTC/Eastern");
59
60 test.equal(helpers.getUTCOffset(m), -300, "Should change the offset when using moment.fn.tz");
61 test.equal(m.format(), "2014-07-10T07:00:00-05:00", "Should change the offset when using moment.fn.tz");
62 test.equal(m.tz(), "TestUTC/Eastern", "Should set the time zone name when using moment.fn.tz");
63
64 m.utcOffset('+02:00')
65
66 test.equal(helpers.getUTCOffset(m), 120, "Should change the offset when using moment.fn.utcOffset");
67 test.equal(m.format(), "2014-07-10T14:00:00+02:00", "Should change the offset when using moment.fn.utcOffset");
68 test.equal(m.tz(), undefined, "Should clear the time zone name when using moment.fn.utcOffset");
69
70 m = moment('2017-01-01T00:00:00');
71 var utcWallTimeFormat = m.clone().utcOffset('-05:00', true).format();
72 m.tz('America/New_York', true);
73 test.equal(m.format(), utcWallTimeFormat, "Should change the offset while keeping wall time when passing an optional parameter to moment.fn.tz");
74
75 test.done();
76 }
77 };