Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
formatTimeFromNumber: function (hourNumber) {
// TODO: this should be able to handle 24 hour and alternate time formats
return date.formatDate(
date.adjustDate(new Date(), { hours: hourNumber }),
'ha'
)
},
moveTimePeriod: function (params) {
set (val) {
val = date.extractDate(val, 'HH:mm')
val = date.adjustDate(this.edit.startDate, { hours: val.getHours(), minutes: val.getMinutes() })
if (val < this.edit.startDate) {
// if the value is in the past add a day (allows pickups over midnight)
val = addDays(val, 1)
}
this.edit.duration = differenceInSeconds(val, this.edit.startDate)
},
},
set (val) {
if (val.length < 5) return
val = date.extractDate(val, 'HH:mm')
val = date.adjustDate(this.edit.date, { hours: val.getHours(), minutes: val.getMinutes() })
if (val <= this.edit.date) {
// if the value is in the past add a day (allows pickups over midnight)
this.edit.dateEnd = addDays(val, 1)
return
}
const duration = differenceInSeconds(val, this.edit.date)
const twentyFourHours = 24 * 60 * 60
if (duration > twentyFourHours) {
const cappedDuration = duration % twentyFourHours
this.edit.dateEnd = addSeconds(this.edit.date, cappedDuration)
return
}
this.edit.dateEnd = val
},
set (val) {
val = date.extractDate(val, 'HH:mm')
val = date.adjustDate(this.edit.startDate, { hours: val.getHours(), minutes: val.getMinutes() })
this.edit.startDate = val
},
},
set (val) {
val = date.extractDate(val, 'YYYY-MM-DD')
val = date.adjustDate(this.edit.startDate, { year: val.getFullYear(), month: val.getMonth() + 1, date: val.getDate() })
this.edit.startDate = val
},
},
setADateToADay: function (dateObject, addDays) {
let now = new Date()
if (typeof dateObject === 'string') {
dateObject = new Date(dateObject)
}
dateObject = date.adjustDate(
dateObject, {
year: now.getFullYear(),
month: now.getMonth() + 1,
date: now.getDate()
}
)
if (addDays !== undefined) {
dateObject = date.addToDate(
dateObject, {
days: addDays
}
)
}
return dateObject
},
getSqlDateFormat: function (dateObject, withTime) {
set (val) {
val = date.extractDate(val, 'HH:mm')
val = date.adjustDate(this.edit.date, { hours: val.getHours(), minutes: val.getMinutes() })
this.date = val
},
},