Skip to content

Commit

Permalink
Merge pull request jquense#60 from Alaneor/failing-test-isodate
Browse files Browse the repository at this point in the history
Fix incorrect leading-zero millisecond conversion
  • Loading branch information
jquense authored Aug 30, 2016
2 parents bb5b8a5 + 1fdf879 commit dab47a9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/util/isodate.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default function parseIsoDate(date) {
struct[3] = +struct[3] || 1;

// allow arbitrary sub-second precision beyond milliseconds
struct[7] = struct[7] ? + (struct[7] + '00').substr(0, 3) : 0;
struct[7] = struct[7] ? String(struct[7]).substr(0, 3) : 0;

// timestamps without timezone identifiers should be considered local time
if ((struct[8] === undefined || struct[8] === '') && (struct[9] === undefined || struct[9] === ''))
Expand Down
4 changes: 4 additions & 0 deletions test/date.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ describe('Date types', function(){
inst.cast(new Date()).should.be.a('date')
inst.cast('jan 15 2014').should.eql(new Date(2014, 0, 15))
inst.cast('2014-09-23T19:25:25Z').should.eql(new Date(1411500325000))
// Leading-zero milliseconds
inst.cast('2016-08-10T11:32:19.012Z').should.eql(new Date(1470828739012))
// Microsecond precision
inst.cast('2016-08-10T11:32:19.2125Z').should.eql(new Date(1470828739212))
})

it('should return invalid date for failed casts', function(){
Expand Down

0 comments on commit dab47a9

Please sign in to comment.