Skip to content

Commit

Permalink
Add check for whether the last item in the untils in filterYears is n…
Browse files Browse the repository at this point in the history
…ull to better mirror the actual data in data/unpacked/{version}.json
  • Loading branch information
timrwood committed Jun 19, 2014
1 parent cf99a77 commit 25a6389
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 48 deletions.
2 changes: 1 addition & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"asi" : false,
"boss" : false,
"debug" : false,
"eqnull" : false,
"eqnull" : true,
"es5" : false,
"esnext" : false,
"evil" : false,
Expand Down
10 changes: 8 additions & 2 deletions moment-timezone-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,9 @@
}

for (i = 0; i < untils.length; i++) {
if (untils[i] == null) {
continue;
}
untilYear = new Date(untils[i]).getUTCFullYear();
if (untilYear < start) {
startI = i + 1;
Expand All @@ -231,12 +234,15 @@

function filterYears (source, start, end) {
var slice = Array.prototype.slice,
indices = findStartAndEndIndex(source.untils, start, end);
indices = findStartAndEndIndex(source.untils, start, end),
untils = slice.apply(source.untils, indices);

untils[untils.length - 1] = null;

return {
name : source.name,
abbrs : slice.apply(source.abbrs, indices),
untils : slice.call(source.untils, indices[0], indices[1] - 1),
untils : untils,
offsets : slice.apply(source.offsets, indices)
};
}
Expand Down
98 changes: 53 additions & 45 deletions tests/moment-timezone/filter-years.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ function unpacked () {
abbrs : ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J"],
offsets : [ 60, 120, 180, 240, 300, 360, 420, 480, 540, 600],
untils : [
+Date.UTC(1900, 0, 1),
+Date.UTC(1900, 6, 15),
+Date.UTC(2000, 0, 1),
+Date.UTC(2000, 6, 15),
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1),
+Date.UTC(2002, 0, 1),
+Date.UTC(2005, 0, 1)
Date.UTC(1900, 0, 1),
Date.UTC(1900, 6, 15),
Date.UTC(2000, 0, 1),
Date.UTC(2000, 6, 15),
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
Date.UTC(2002, 0, 1),
Date.UTC(2005, 0, 1),
null
]
};
}
Expand All @@ -29,13 +30,14 @@ exports['filter-years'] = {
abbrs : ["C", "D", "E", "F", "G", "H", "I", "J"],
offsets : [180, 240, 300, 360, 420, 480, 540, 600],
untils : [
+Date.UTC(2000, 0, 1),
+Date.UTC(2000, 6, 15),
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1),
+Date.UTC(2002, 0, 1),
+Date.UTC(2005, 0, 1)
Date.UTC(2000, 0, 1),
Date.UTC(2000, 6, 15),
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
Date.UTC(2002, 0, 1),
Date.UTC(2005, 0, 1),
null
]
};

Expand All @@ -51,13 +53,14 @@ exports['filter-years'] = {
abbrs : ["C", "D", "E", "F", "G", "H", "I", "J"],
offsets : [180, 240, 300, 360, 420, 480, 540, 600],
untils : [
+Date.UTC(2000, 0, 1),
+Date.UTC(2000, 6, 15),
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1),
+Date.UTC(2002, 0, 1),
+Date.UTC(2005, 0, 1)
Date.UTC(2000, 0, 1),
Date.UTC(2000, 6, 15),
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
Date.UTC(2002, 0, 1),
Date.UTC(2005, 0, 1),
null
]
};

Expand All @@ -73,11 +76,12 @@ exports['filter-years'] = {
abbrs : ["E", "F", "G", "H", "I", "J"],
offsets : [300, 360, 420, 480, 540, 600],
untils : [
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1),
+Date.UTC(2002, 0, 1),
+Date.UTC(2005, 0, 1)
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
Date.UTC(2002, 0, 1),
Date.UTC(2005, 0, 1),
null
]
};

Expand All @@ -93,11 +97,12 @@ exports['filter-years'] = {
abbrs : ["C", "D", "E", "F", "G", "H"],
offsets : [180, 240, 300, 360, 420, 480],
untils : [
+Date.UTC(2000, 0, 1),
+Date.UTC(2000, 6, 15),
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1)
Date.UTC(2000, 0, 1),
Date.UTC(2000, 6, 15),
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
null
]
};

Expand All @@ -113,11 +118,12 @@ exports['filter-years'] = {
abbrs : ["C", "D", "E", "F", "G", "H"],
offsets : [180, 240, 300, 360, 420, 480],
untils : [
+Date.UTC(2000, 0, 1),
+Date.UTC(2000, 6, 15),
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1)
Date.UTC(2000, 0, 1),
Date.UTC(2000, 6, 15),
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
null
]
};

Expand All @@ -133,8 +139,9 @@ exports['filter-years'] = {
abbrs : ["C", "D", "E"],
offsets : [180, 240, 300],
untils : [
+Date.UTC(2000, 0, 1),
+Date.UTC(2000, 6, 15)
Date.UTC(2000, 0, 1),
Date.UTC(2000, 6, 15),
null
]
};

Expand All @@ -150,11 +157,12 @@ exports['filter-years'] = {
abbrs : ["E", "F", "G", "H", "I", "J"],
offsets : [300, 360, 420, 480, 540, 600],
untils : [
+Date.UTC(2001, 0, 1),
+Date.UTC(2001, 6, 15),
+Date.UTC(2001, 8, 1),
+Date.UTC(2002, 0, 1),
+Date.UTC(2005, 0, 1)
Date.UTC(2001, 0, 1),
Date.UTC(2001, 6, 15),
Date.UTC(2001, 8, 1),
Date.UTC(2002, 0, 1),
Date.UTC(2005, 0, 1),
null
]
};

Expand Down

0 comments on commit 25a6389

Please sign in to comment.