Skip to content

Commit

Permalink
Fixed potential limitation in pull request #27
Browse files Browse the repository at this point in the history
Not a bug but possibly a limitation for certain date formats.
  • Loading branch information
johnkiernander committed Nov 22, 2013
1 parent 5cb73e7 commit 61119bb
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/objects/axis/methods/_parseDate.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@
this._parseDate = function (inDate) {
// A javascript date object
var outDate;
if (!isNaN(inDate)) {
// If inDate is a number, assume it's epoch time
outDate = new Date(inDate);
} else if (this.dateParseFormat === null || this.dateParseFormat === undefined) {
// If nothing has been explicity defined you are in the hands of the browser gods
// may they smile upon you...
outDate = Date.parse(inDate);
if (this.dateParseFormat === null || this.dateParseFormat === undefined) {
// Moved this into the condition so that using epoch time requires no data format to be set.
// For example 20131122 might be parsed as %Y%m%d not treated as epoch time.
if (!isNaN(inDate)) {
// If inDate is a number, assume it's epoch time
outDate = new Date(inDate);
} else {
// If nothing has been explicity defined you are in the hands of the browser gods
// may they smile upon you...
outDate = Date.parse(inDate);
}
} else {
outDate = d3.time.format(this.dateParseFormat).parse(inDate);
}
Expand Down

1 comment on commit 61119bb

@dule
Copy link
Contributor

@dule dule commented on 61119bb Nov 22, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh whoops, I didn't realize isNaN returned false if a string is a number. Perhaps I should have done a typeof inDate === 'number' check instead.

Please sign in to comment.