Debian Codegraph @

tests/moment-timezone/add.js

raw symbols SCIP
1 "use strict";
2
3 var moment = require("../../"),
4 tz = moment.tz;
5
6 exports.add = {
7 adding : function (test) {
8 // gE = 1000; 1E = 100; 2k = 140
9 tz.add("SomeZone|TIM TAM IAM|60.u 50 60|012101|gE 1E 2k 1E 2k");
10
11 var zone = tz.zone("SomeZone");
12
13 test.ok(zone, "Add a zone with tz.add(string) and get it back with tz.zone(name).");
14 test.equal(zone.name, "SomeZone", "Should unpack name onto .name property.");
15 test.deepEqual(zone.abbrs, ["TIM", "TAM", "IAM", "TAM", "TIM", "TAM"], "Should unpack abbrs onto .abbrs property.");
16 test.deepEqual(zone.offsets, [360.5, 300, 360, 300, 360.5, 300], "Should unpack offsets onto .offsets property.");
17 test.deepEqual(zone.untils, [
18 1000 * 60000,
19 1100 * 60000,
20 1240 * 60000,
21 1340 * 60000,
22 1480 * 60000,
23 Infinity
24 ], "Should unpack untils onto .untils property.");
25
26 test.done();
27 },
28
29 addingMany : function (test) {
30 tz.add([
31 "AddingMany/Test1|QWE RTY|60 30|0101|-30 10 8",
32 "AddingMany/Test2|QWE RTY|60 30|1010|-30 10 8",
33 "AddingMany/Test3|QWE RTY|60 30|0101|-30 10 8"
34 ]);
35 tz.add("AddingMany/Test4|QWE RTY|60 30|0101|-30 10 8");
36
37 test.ok(tz.zone("AddingMany/Test1"), "Should be able to add items in an array of strings.");
38 test.ok(tz.zone("AddingMany/Test2"), "Should be able to add items in an array of strings.");
39 test.ok(tz.zone("AddingMany/Test3"), "Should be able to add items in an array of strings.");
40 test.ok(tz.zone("AddingMany/Test4"), "Should be able to add an item in a single string.");
41
42 test.done();
43 },
44
45 caching : function (test) {
46 tz._zones.somezone = undefined;
47
48 test.equal(tz.zone("SomeZone"), null, "If moment.tz._zones does not have an zone, tz.zone(name) should return null.");
49
50 // gE = 1000; 1E = 100; 2k = 140
51 tz.add("SomeZone|TIM TAM IAM|60.u 50 60|012101|gE 1E 2k 1E 2k");
52
53 test.ok(tz.zone("SomeZone"), "Should be able to add and retrieve a zone.");
54 test.ok(tz._zones.somezone, "The cache should be updated when adding a zone.");
55
56 test.done();
57 },
58
59 caseInsensitive : function (test) {
60 tz.add("CASE_INSENSITIVE|ASD|60|0|234");
61
62 test.ok(tz.zone('case_insensitive'), "getting zones should not be case sensitive.");
63 test.ok(tz.zone('Case_Insensitive'), "getting zones should not be case sensitive.");
64 test.ok(tz.zone('case/insensitive'), "getting zones should not differentiate between _ and /.");
65
66 tz.add("Case/Insens_Itive2|ASD|60|0|234");
67
68 test.ok(tz.zone('CASE_insens_itive2'), "getting zones should not be case sensitive.");
69 test.ok(tz.zone('case_insens_itive2'), "getting zones should not be case sensitive.");
70 test.ok(tz.zone('Case_Insens_itive2'), "getting zones should not be case sensitive.");
71 test.ok(tz.zone('case/insens/itive2'), "getting zones should not differentiate between _ and /.");
72
73 test.done();
74 },
75
76 missingZone : function (test) {
77 if (typeof console === 'undefined') {
78 test.done();
79 return;
80 }
81
82 var oldError = console.error,
83 errors = '';
84
85 console.error = function (message) {
86 errors += message;
87 };
88
89 moment().tz('Not_A/Loaded_Zone');
90
91 test.equal(errors, "Moment Timezone has no data for Not_A/Loaded_Zone. See http://momentjs.com/timezone/docs/#/data-loading/.");
92
93 errors = '';
94
95 tz('Another/Unloaded_Zone');
96
97 test.equal(errors, "Moment Timezone has no data for Another/Unloaded_Zone. See http://momentjs.com/timezone/docs/#/data-loading/.");
98
99 console.error = oldError;
100
101 test.done();
102 }
103 };