Skip to content

Commit

Permalink
Merge 8ea5c0b into 7cc1c32
Browse files Browse the repository at this point in the history
  • Loading branch information
wmcmurray committed Mar 1, 2019
2 parents 7cc1c32 + 8ea5c0b commit f418c37
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/components/DateInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export default {
id: String,
name: String,
refName: String,
openDate: Date,
openDate: {
validator: (val) => {
return val === null || val instanceof Date || typeof val === 'string' || typeof val === 'number'
}
},
placeholder: String,
inputClass: [String, Object, Array],
clearButton: Boolean,
Expand Down
6 changes: 4 additions & 2 deletions src/components/Datepicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ export default {
data () {
const startDate = this.openDate ? new Date(this.openDate) : new Date()
const constructedDateUtils = makeDateUtils(this.useUtc)
constructedDateUtils.resetDateTime(startDate)
const pageTimestamp = constructedDateUtils.setDate(startDate, 1)
return {
/*
Expand All @@ -182,7 +183,7 @@ export default {
* Positioning
*/
calendarHeight: 0,
resetTypedDate: new Date(),
resetTypedDate: constructedDateUtils.getNewDateObject(),
utils: constructedDateUtils
}
},
Expand Down Expand Up @@ -351,7 +352,7 @@ export default {
if (!this.isInline) {
this.close(true)
}
this.resetTypedDate = new Date()
this.resetTypedDate = this.utils.getNewDateObject()
},
/**
* @param {Object} date
Expand Down Expand Up @@ -412,6 +413,7 @@ export default {
} else {
date = new Date()
}
this.utils.resetDateTime(date)
}
this.pageTimestamp = this.utils.setDate(new Date(date), 1)
},
Expand Down
2 changes: 1 addition & 1 deletion src/components/PickerDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ export default {
isHighlighted: this.isHighlightedDate(dObj),
isHighlightStart: this.isHighlightStart(dObj),
isHighlightEnd: this.isHighlightEnd(dObj),
isToday: this.utils.compareDates(dObj, new Date()),
isToday: this.utils.compareDates(dObj, this.utils.getNewDateObject()),
isWeekend: this.utils.getDay(dObj) === 0 || this.utils.getDay(dObj) === 6,
isSaturday: this.utils.getDay(dObj) === 6,
isSunday: this.utils.getDay(dObj) === 0
Expand Down
34 changes: 27 additions & 7 deletions src/utils/DateUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ const utils = {
const d1 = new Date(date1.getTime())
const d2 = new Date(date2.getTime())

if (this.useUtc) {
d1.setUTCHours(0, 0, 0, 0)
d2.setUTCHours(0, 0, 0, 0)
} else {
d1.setHours(0, 0, 0, 0)
d2.setHours(0, 0, 0, 0)
}
this.resetDateTime(d1)
this.resetDateTime(d2)

return d1.getTime() === d2.getTime()
},

Expand Down Expand Up @@ -240,6 +236,30 @@ const utils = {
*/
validateDateInput (val) {
return val === null || val instanceof Date || typeof val === 'string' || typeof val === 'number'
},

/**
* Remove hours/minutes/seconds/milliseconds from a date object
* @param {Date} date
* @return {Date}
*/
resetDateTime (date) {
if (this.useUtc) {
date.setUTCHours(0, 0, 0, 0)
} else {
date.setHours(0, 0, 0, 0)
}
return date
},

/**
* Return a new date object with hours/minutes/seconds/milliseconds removed
* @return {Date}
*/
getNewDateObject () {
var d = new Date()
this.resetDateTime(d)
return d
}
}

Expand Down

0 comments on commit f418c37

Please sign in to comment.