Skip to content

Commit

Permalink
fix(utils): resolve typeable date timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
MrWook committed Nov 9, 2020
1 parent 78f331e commit 68998cc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/utils/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -289,13 +289,21 @@ const utils = {
ymd[2] = tmp < 10 ? `0${tmp}` : `${tmp}`
}
}
const dat = `${ymd.join('-')}T00:00:00Z`
const dat = `${ymd.join('-')}${this.getZeroTime()}`
if (Number.isNaN(Date.parse(dat))) {
return dateStr
}
return dat
},

getZeroTime() {
const time = 'T00:00:00'
if (this.useUtc) {
return `${time}Z`
}
return time
},

/**
* Creates an array of dates for each day in between two dates.
* @param {Date} start
Expand Down
15 changes: 10 additions & 5 deletions test/unit/specs/DateUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,15 +62,15 @@ describe('DateUtils', () => {

it('should parse english dates', () => {
expect(DateUtils.parseDate('16 April 2020', 'd MMMM yyyy', en, null))
.toEqual('2020-04-16T00:00:00Z')
.toEqual('2020-04-16T00:00:00')
expect(DateUtils.parseDate('16th Apr 2020', 'do MMM yyyy', en, null))
.toEqual('2020-04-16T00:00:00Z')
.toEqual('2020-04-16T00:00:00')
expect(DateUtils.parseDate('Thu 16th Apr 2020', 'E do MMM yyyy', en, null))
.toEqual('2020-04-16T00:00:00Z')
.toEqual('2020-04-16T00:00:00')
expect(DateUtils.parseDate('16.04.2020', 'dd.MM.yyyy', en, null))
.toEqual('2020-04-16T00:00:00Z')
.toEqual('2020-04-16T00:00:00')
expect(DateUtils.parseDate('04.16.2020', 'MM.dd.yyyy', en, null))
.toEqual('2020-04-16T00:00:00Z')
.toEqual('2020-04-16T00:00:00')
})

it('should fail to parse because of missing parser', () => {
Expand Down Expand Up @@ -225,4 +225,9 @@ describe('UTC functions', () => {
expect(DateUtils.getDayFromAbbr('sat')).toEqual(6)
expect(() => DateUtils.getDayFromAbbr('nonsense')).toThrow('Invalid week day')
})

it('getZeroTime', () => {
expect(DateUtils.getZeroTime()).toEqual('T00:00:00')
expect(utcUtils.getZeroTime()).toEqual('T00:00:00Z')
})
})

0 comments on commit 68998cc

Please sign in to comment.