Debian Codegraph @

tests/moment-timezone/default.js

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 "use strict";
2
3 var moment = require("../../");
4
5 exports.default = {
6 defaultZone : function (t) {
7 t.equal(
8 moment.defaultZone,
9 null,
10 'initial default zone should be null'
11 );
12 t.equal(
13 moment.tz.setDefault('America/New_York').defaultZone.name,
14 'America/New_York',
15 'calling moment.tz.setDefault with a valid timezone should expose it via defaultZone'
16 );
17 t.equal(
18 moment.tz.setDefault().defaultZone,
19 null,
20 'calling moment.tz.setDefault with a falsey argument should unset defaultZone'
21 );
22 t.done();
23 },
24 normal: function (t) {
25 moment.tz.setDefault('America/New_York');
26 var m = moment();
27 t.equal(
28 m._z.name,
29 'America/New_York',
30 'creating moments should set their default timezone if it is set'
31 );
32
33 moment.tz.setDefault();
34 var m2 = moment();
35 moment.tz.setDefault('America/New_York');
36 m2.millisecond(0);
37 t.equal(
38 m2._z,
39 null,
40 'calling updateOffset on moments created before setting a default timezone should not affect their timezone'
41 );
42 moment.tz.setDefault();
43 t.done();
44 },
45 utc : function (t) {
46 moment.tz.setDefault('America/New_York');
47 t.equal(
48 moment.utc().format('ZZ'),
49 '+0000',
50 'creating moments in UTC mode should ignore default timezone'
51 );
52 t.notEqual(
53 moment().format('ZZ'),
54 '+0000',
55 'using UTC mode should not affect normal moment creation'
56 );
57
58 var utc_moment = moment.utc(),
59 normal_moment = moment(),
60 normal_moment_offset = normal_moment.format('ZZ');
61 moment.tz.setDefault();
62 utc_moment.millisecond(0);
63 normal_moment.millisecond(0);
64 t.equal(
65 utc_moment.format('ZZ'),
66 '+0000',
67 'resetting default timezone should not affect existing moments created in UTC mode'
68 );
69 t.equal(
70 normal_moment.format('ZZ'),
71 normal_moment_offset,
72 'resetting default timezone should not affect existing moments'
73 );
74 t.done();
75 },
76 valueOf : function (t) {
77 moment.tz.setDefault();
78 t.ok(
79 Number.isNaN(moment('2023/10/06', ['H', 'HH', 'HH:mm'], true).valueOf()),
80 'invalid moment should return NaN for .valueOf()'
81 );
82 // https://github.com/moment/moment-timezone/issues/1075
83 moment.tz.setDefault('America/New_York');
84 t.ok(
85 Number.isNaN(moment('2023/10/06', ['H', 'HH', 'HH:mm'], true).valueOf()),
86 'invalid moment with default zone should return NaN for .valueOf()'
87 );
88 t.done();
89 }
90 };