Skip to content

Commit 5c5c01a

Browse files
committed
more defensive coding for invalid dates
1 parent 101796a commit 5c5c01a

File tree

1 file changed

+26
-25
lines changed

1 file changed

+26
-25
lines changed

jquery.ganttView.js

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -162,30 +162,30 @@ slideWidth: number
162162
for (var j = 0; j < data[i].series.length; j++) {
163163
var series = data[i].series[j];
164164
var size = DateUtils.daysBetween(series.start, series.end);
165-
if (size && size > 0) {
166-
if (size > 365) { size = 365; } // Keep blocks from overflowing a year
167-
var offset = DateUtils.daysBetween(start, series.start);
168-
var blockDiv = jQuery("<div>", {
169-
"class": "ganttview-block",
170-
"title": series.name + ", " + size + " days",
171-
"css": {
172-
"width": ((size * cellWidth) - 9) + "px",
173-
"margin-left": ((offset * cellWidth) + 3) + "px"
174-
}
175-
}).data("block-data", {
176-
id: data[i].id,
177-
itemName: data[i].name,
178-
seriesName: series.name,
179-
start: Date.parse(series.start),
180-
end: Date.parse(series.end),
181-
color: series.color
182-
});
183-
if (data[i].series[j].color) {
184-
blockDiv.css("background-color", data[i].series[j].color);
185-
}
186-
blockDiv.append($("<div>", { "class": "ganttview-block-text" }).text(size));
187-
jQuery(rows[rowIdx]).append(blockDiv);
188-
}
165+
if (size && size > 0) {
166+
if (size > 365) { size = 365; } // Keep blocks from overflowing a year
167+
var offset = DateUtils.daysBetween(start, series.start);
168+
var blockDiv = jQuery("<div>", {
169+
"class": "ganttview-block",
170+
"title": series.name + ", " + size + " days",
171+
"css": {
172+
"width": ((size * cellWidth) - 9) + "px",
173+
"margin-left": ((offset * cellWidth) + 3) + "px"
174+
}
175+
}).data("block-data", {
176+
id: data[i].id,
177+
itemName: data[i].name,
178+
seriesName: series.name,
179+
start: Date.parse(series.start),
180+
end: Date.parse(series.end),
181+
color: series.color
182+
});
183+
if (data[i].series[j].color) {
184+
blockDiv.css("background-color", data[i].series[j].color);
185+
}
186+
blockDiv.append($("<div>", { "class": "ganttview-block-text" }).text(size));
187+
jQuery(rows[rowIdx]).append(blockDiv);
188+
}
189189
rowIdx = rowIdx + 1;
190190
}
191191
}
@@ -218,8 +218,9 @@ slideWidth: number
218218

219219
var DateUtils = {
220220
daysBetween: function (start, end) {
221-
if (!start || !end) return 0;
221+
if (!start || !end) { return 0; }
222222
start = Date.parse(start); end = Date.parse(end);
223+
if (start.getYear() == 1901 || end.getYear() == 8099) { return 0; }
223224
var count = 0, date = start.clone();
224225
while (date.compareTo(end) == -1) { count = count + 1; date.addDays(1); }
225226
return count;

0 commit comments

Comments
 (0)