| 1 |
"use strict"; |
| 2 |
|
| 3 |
var tz = require("../../moment-timezone-utils").tz; |
| 4 |
|
| 5 |
function unpacked () { |
| 6 |
return { |
| 7 |
name : "Some/Zone_Name", |
| 8 |
abbrs : ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"], |
| 9 |
offsets : [ 60, 120, 180, 240, 300, 360, 420, 480, 540, 600], |
| 10 |
untils : [ |
| 11 |
Date.UTC(1900, 0, 1), |
| 12 |
Date.UTC(1900, 6, 15), |
| 13 |
Date.UTC(2000, 0, 1), |
| 14 |
Date.UTC(2000, 6, 15), |
| 15 |
Date.UTC(2001, 0, 1), |
| 16 |
Date.UTC(2001, 6, 15), |
| 17 |
Date.UTC(2001, 8, 1), |
| 18 |
Date.UTC(2002, 0, 1), |
| 19 |
Date.UTC(2005, 0, 1), |
| 20 |
null |
| 21 |
] |
| 22 |
}; |
| 23 |
} |
| 24 |
|
| 25 |
exports['filter-years'] = { |
| 26 |
'filter 1970-2038' : function (test) { |
| 27 |
var actual = tz.filterYears(unpacked(), 1970, 2038), |
| 28 |
expected = { |
| 29 |
name : "Some/Zone_Name", |
| 30 |
abbrs : ["C", "D", "E", "F", "G", "H", "I", "J"], |
| 31 |
offsets : [180, 240, 300, 360, 420, 480, 540, 600], |
| 32 |
untils : [ |
| 33 |
Date.UTC(2000, 0, 1), |
| 34 |
Date.UTC(2000, 6, 15), |
| 35 |
Date.UTC(2001, 0, 1), |
| 36 |
Date.UTC(2001, 6, 15), |
| 37 |
Date.UTC(2001, 8, 1), |
| 38 |
Date.UTC(2002, 0, 1), |
| 39 |
Date.UTC(2005, 0, 1), |
| 40 |
null |
| 41 |
], |
| 42 |
population: undefined, |
| 43 |
countries: undefined |
| 44 |
}; |
| 45 |
|
| 46 |
test.deepEqual(actual, expected, "Should be able to filter out years outside the 1970-2038 range"); |
| 47 |
|
| 48 |
test.done(); |
| 49 |
}, |
| 50 |
|
| 51 |
'filter 2000-2038' : function (test) { |
| 52 |
var actual = tz.filterYears(unpacked(), 2000, 2038), |
| 53 |
expected = { |
| 54 |
name : "Some/Zone_Name", |
| 55 |
abbrs : ["C", "D", "E", "F", "G", "H", "I", "J"], |
| 56 |
offsets : [180, 240, 300, 360, 420, 480, 540, 600], |
| 57 |
untils : [ |
| 58 |
Date.UTC(2000, 0, 1), |
| 59 |
Date.UTC(2000, 6, 15), |
| 60 |
Date.UTC(2001, 0, 1), |
| 61 |
Date.UTC(2001, 6, 15), |
| 62 |
Date.UTC(2001, 8, 1), |
| 63 |
Date.UTC(2002, 0, 1), |
| 64 |
Date.UTC(2005, 0, 1), |
| 65 |
null |
| 66 |
], |
| 67 |
population: undefined, |
| 68 |
countries: undefined |
| 69 |
}; |
| 70 |
|
| 71 |
test.deepEqual(actual, expected, "Should be able to filter out years outside the 2000-2038 range"); |
| 72 |
|
| 73 |
test.done(); |
| 74 |
}, |
| 75 |
|
| 76 |
'filter 2001-2038' : function (test) { |
| 77 |
var actual = tz.filterYears(unpacked(), 2001, 2038), |
| 78 |
expected = { |
| 79 |
name : "Some/Zone_Name", |
| 80 |
abbrs : ["E", "F", "G", "H", "I", "J"], |
| 81 |
offsets : [300, 360, 420, 480, 540, 600], |
| 82 |
untils : [ |
| 83 |
Date.UTC(2001, 0, 1), |
| 84 |
Date.UTC(2001, 6, 15), |
| 85 |
Date.UTC(2001, 8, 1), |
| 86 |
Date.UTC(2002, 0, 1), |
| 87 |
Date.UTC(2005, 0, 1), |
| 88 |
null |
| 89 |
], |
| 90 |
population: undefined, |
| 91 |
countries: undefined |
| 92 |
}; |
| 93 |
|
| 94 |
test.deepEqual(actual, expected, "Should be able to filter out years outside the 2001-2038 range"); |
| 95 |
|
| 96 |
test.done(); |
| 97 |
}, |
| 98 |
|
| 99 |
'filter 2000-2001' : function (test) { |
| 100 |
var actual = tz.filterYears(unpacked(), 2000, 2001), |
| 101 |
expected = { |
| 102 |
name : "Some/Zone_Name", |
| 103 |
abbrs : ["C", "D", "E", "F", "G", "H"], |
| 104 |
offsets : [180, 240, 300, 360, 420, 480], |
| 105 |
untils : [ |
| 106 |
Date.UTC(2000, 0, 1), |
| 107 |
Date.UTC(2000, 6, 15), |
| 108 |
Date.UTC(2001, 0, 1), |
| 109 |
Date.UTC(2001, 6, 15), |
| 110 |
Date.UTC(2001, 8, 1), |
| 111 |
null |
| 112 |
], |
| 113 |
population: undefined, |
| 114 |
countries: undefined |
| 115 |
}; |
| 116 |
|
| 117 |
test.deepEqual(actual, expected, "Should be able to filter out years outside the 2000-2001 range"); |
| 118 |
|
| 119 |
test.done(); |
| 120 |
}, |
| 121 |
|
| 122 |
'filter 2001-2000' : function (test) { |
| 123 |
var actual = tz.filterYears(unpacked(), 2001, 2000), |
| 124 |
expected = { |
| 125 |
name : "Some/Zone_Name", |
| 126 |
abbrs : ["C", "D", "E", "F", "G", "H"], |
| 127 |
offsets : [180, 240, 300, 360, 420, 480], |
| 128 |
untils : [ |
| 129 |
Date.UTC(2000, 0, 1), |
| 130 |
Date.UTC(2000, 6, 15), |
| 131 |
Date.UTC(2001, 0, 1), |
| 132 |
Date.UTC(2001, 6, 15), |
| 133 |
Date.UTC(2001, 8, 1), |
| 134 |
null |
| 135 |
], |
| 136 |
population: undefined, |
| 137 |
countries: undefined |
| 138 |
}; |
| 139 |
|
| 140 |
test.deepEqual(actual, expected, "Should be able to handle the years passed in as end, start instead of start, end"); |
| 141 |
|
| 142 |
test.done(); |
| 143 |
}, |
| 144 |
|
| 145 |
'filter 2000' : function (test) { |
| 146 |
var actual = tz.filterYears(unpacked(), 2000), |
| 147 |
expected = { |
| 148 |
name : "Some/Zone_Name", |
| 149 |
abbrs : ["C", "D", "E"], |
| 150 |
offsets : [180, 240, 300], |
| 151 |
untils : [ |
| 152 |
Date.UTC(2000, 0, 1), |
| 153 |
Date.UTC(2000, 6, 15), |
| 154 |
null |
| 155 |
], |
| 156 |
population: undefined, |
| 157 |
countries: undefined |
| 158 |
}; |
| 159 |
|
| 160 |
test.deepEqual(actual, expected, "Should be able to use the same start and end year if only one year was passed in"); |
| 161 |
|
| 162 |
test.done(); |
| 163 |
}, |
| 164 |
|
| 165 |
'filter 2001-2005' : function (test) { |
| 166 |
var actual = tz.filterYears(unpacked(), 2001, 2005), |
| 167 |
expected = { |
| 168 |
name : "Some/Zone_Name", |
| 169 |
abbrs : ["E", "F", "G", "H", "I", "J"], |
| 170 |
offsets : [300, 360, 420, 480, 540, 600], |
| 171 |
untils : [ |
| 172 |
Date.UTC(2001, 0, 1), |
| 173 |
Date.UTC(2001, 6, 15), |
| 174 |
Date.UTC(2001, 8, 1), |
| 175 |
Date.UTC(2002, 0, 1), |
| 176 |
Date.UTC(2005, 0, 1), |
| 177 |
null |
| 178 |
], |
| 179 |
population: undefined, |
| 180 |
countries: undefined |
| 181 |
}; |
| 182 |
|
| 183 |
test.deepEqual(actual, expected, "Should be able to filter out years outside the 2000-2005 range"); |
| 184 |
|
| 185 |
test.done(); |
| 186 |
} |
| 187 |
}; |