Prevent datepicker from crashing when using date only and the timezone is not UTC

This commit is contained in:
Jože Fortun
2023-01-18 13:13:41 +01:00
parent 81ea895b82
commit 8cbae6ef29
2 changed files with 7 additions and 7 deletions
@@ -53,11 +53,7 @@ export class ModuleFieldDateTime extends ModuleField {
}
const o = this.options
let m = moment(value)
if (o.onlyTime) {
m = moment(value, ['YYYY-MM-DD HH:mm', 'YYYY-MM-DD', 'HH:mm'])
}
const m = moment(value, ['YYYY-MM-DDTHH:mm:ssZ', 'YYYY-MM-DD HH:mm', 'YYYY-MM-DD', 'HH:mm'])
if (o.outputRelative) {
return m.fromNow()
@@ -66,7 +62,7 @@ export class ModuleFieldDateTime extends ModuleField {
} else if (o.onlyTime) {
return fmt.time(m)
} else if (o.onlyDate) {
return fmt.date(m)
return fmt.date(moment(value, 'YYYY-MM-DD'))
} else {
return fmt.fullDateTime(m)
}
@@ -10,7 +10,11 @@ export function getDate (value: string|undefined): string | undefined {
return undefined
}
return moment.utc(value).local().format('YYYY-MM-DD')
if (moment(value, 'YYYY-MM-DDTHH:mm:ssZ', true).isValid()) {
return moment.utc(value).local().format('YYYY-MM-DD')
}
return value
}
export function getTime (value: string|undefined): string | undefined {