Debian Codegraph @

tests/moment-timezone/zone.js

raw symbols SCIP
1 "use strict";
2
3 var tz = require("../../").tz;
4
5 // gE = 1000; 1E = 100; 2k = 140
6 var PACKED = "SomeZone|TIM TAM IAM|60.u 50 60|012101|gE 1E 2k 1E 2k";
7
8 var moveAmbiguousForward, moveInvalidForward;
9
10 exports.zone = {
11 setUp : function (done) {
12 moveAmbiguousForward = tz.moveAmbiguousForward;
13 moveInvalidForward = tz.moveInvalidForward;
14 done();
15 },
16
17 tearDown : function (done) {
18 tz.moveAmbiguousForward = moveAmbiguousForward;
19 tz.moveInvalidForward = moveInvalidForward;
20 done();
21 },
22
23 construct : function (test) {
24 var zone = new tz.Zone(PACKED);
25
26 test.equal(zone.name, "SomeZone", "Should unpack name onto .name property.");
27 test.deepEqual(zone.abbrs, ["TIM", "TAM", "IAM", "TAM", "TIM", "TAM"], "Should unpack abbrs onto .abbrs property.");
28 test.deepEqual(zone.offsets, [360.5, 300, 360, 300, 360.5, 300], "Should unpack offsets onto .offsets property.");
29 test.deepEqual(zone.untils, [
30 1000 * 60000,
31 1100 * 60000,
32 1240 * 60000,
33 1340 * 60000,
34 1480 * 60000,
35 Infinity
36 ], "Should unpack untils onto .untils property.");
37
38 test.done();
39 },
40
41 abbr : function (test) {
42 var zone = new tz.Zone(PACKED),
43 tests = [
44 [-999 * 60000, "TIM"],
45 [ 999 * 60000, "TIM"],
46 [1000 * 60000, "TAM"],
47 [1099 * 60000, "TAM"],
48 [1100 * 60000, "IAM"],
49 [1239 * 60000, "IAM"],
50 [1240 * 60000, "TAM"],
51 [1339 * 60000, "TAM"],
52 [1340 * 60000, "TIM"],
53 [1479 * 60000, "TIM"],
54 [1480 * 60000, "TAM"],
55 [3000 * 60000, "TAM"]
56 ], i, source, expected;
57
58 for (i = 0; i < tests.length; i++) {
59 source = tests[i][0];
60 expected = tests[i][1];
61 test.equal(zone.abbr(source), expected, "The abbr for " + source + " should be " + expected);
62 }
63
64 test.done();
65 },
66
67 offset : function (test) {
68 var zone = new tz.Zone(PACKED),
69 tests = [
70 [-999 * 60000, 360.5],
71 [ 999 * 60000, 360.5],
72 [1000 * 60000, 300],
73 [1099 * 60000, 300],
74 [1100 * 60000, 360],
75 [1239 * 60000, 360],
76 [1240 * 60000, 300],
77 [1339 * 60000, 300],
78 [1340 * 60000, 360.5],
79 [1479 * 60000, 360.5],
80 [1480 * 60000, 300],
81 [3000 * 60000, 300]
82 ], i, source, expected;
83
84 for (i = 0; i < tests.length; i++) {
85 source = tests[i][0];
86 expected = tests[i][1];
87 test.equal(zone.utcOffset(source), expected, "The offset for " + source + " should be " + expected);
88 }
89
90 test.done();
91 },
92
93 _index : function (test) {
94 var zone = new tz.Zone(PACKED),
95 tests = [
96 [-999 * 60000, 0],
97 [ 999 * 60000, 0],
98 [1000 * 60000, 1],
99 [1099 * 60000, 1],
100 [1100 * 60000, 2],
101 [1239 * 60000, 2],
102 [1240 * 60000, 3],
103 [1339 * 60000, 3],
104 [1340 * 60000, 4],
105 [1479 * 60000, 4],
106 [1480 * 60000, 5],
107 [3000 * 60000, 5]
108 ], i, source, expected;
109
110 for (i = 0; i < tests.length; i++) {
111 source = tests[i][0];
112 expected = tests[i][1];
113 test.equal(zone._index(source), expected, "The _index for " + source + " should be " + expected);
114 }
115
116 test.done();
117 },
118
119 parse : function (test) {
120 var zone = new tz.Zone(PACKED),
121 tests = [
122 [( 999 - 360.5) * 60000, 360.5],
123 [(1000 - 360.5) * 60000, 300],
124
125 [(1099 - 300) * 60000, 300],
126 [(1100 - 300) * 60000, 360],
127
128 [(1239 - 360) * 60000, 360],
129 [(1240 - 360) * 60000, 300],
130
131 [(1339 - 300) * 60000, 300],
132 [(1340 - 300) * 60000, 360.5],
133
134 [(1479 - 360.5) * 60000, 360.5],
135 [(1480 - 360.5) * 60000, 300]
136 ], i, source, expected;
137
138 tz.moveInvalidForward = false;
139
140 for (i = 0; i < tests.length; i++) {
141 source = tests[i][0];
142 expected = tests[i][1];
143 test.equal(zone.parse(source), expected, "The parse for " + source + " should be " + expected);
144 }
145
146 test.done();
147 }
148 };