Skip to content

Commit

Permalink
Merge 453a27f into de0fc75
Browse files Browse the repository at this point in the history
  • Loading branch information
ij1 committed Jul 12, 2019
2 parents de0fc75 + 453a27f commit c4d81cf
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/components/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,10 @@ export default {
}
if (this.typeable) {
const typedDate = Date.parse(this.input.value)
const typedDate = this.utils.parseDate(this.input.value)
if (!isNaN(typedDate)) {
this.typedDate = this.input.value
this.$emit('typedDate', new Date(this.typedDate))
this.$emit('typedDate', new Date(typedDate))
}
}
},
Expand All @@ -130,7 +130,7 @@ export default {
* called once the input is blurred
*/
inputBlurred () {
if (this.typeable && isNaN(Date.parse(this.input.value))) {
if (this.typeable && isNaN(this.utils.parseDate(this.input.value))) {
this.clearDate()
this.input.value = null
this.typedDate = null
Expand Down
9 changes: 9 additions & 0 deletions src/utils/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,15 @@ const utils = {
return str
},

/**
* Parses date string into milliseconds, using UTC or not
* @param {String} dateString
* @return {Number}
*/
parseDate (dateString) {
return Date.parse(this.useUtc ? dateString + ' UTC' : dateString)
},

/**
* Creates an array of dates for each day in between two dates.
* @param {Date} start
Expand Down
7 changes: 7 additions & 0 deletions test/unit/specs/DateUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,4 +180,11 @@ describe('UTC functions', () => {
expect(DateUtils.setDate(date, 31)).toEqual(date.setDate(31))
expect(utcUtils.setDate(date, 31)).toEqual(date.setUTCDate(31))
})

it('parseDate', () => {
const date = '2018/11/30'
expect((new Date(DateUtils.parseDate(date))).getDate()).toEqual(30)
expect((new Date(utcUtils.parseDate(date))).getUTCDate()).toEqual(30)
expect(utcUtils.parseDate(date)).toEqual(DateUtils.parseDate(date) - (new Date(utcUtils.parseDate(date))).getTimezoneOffset() * 60 * 1000)
})
})

0 comments on commit c4d81cf

Please sign in to comment.