Fix Et2DateTimeOnly displayed 00:00 when value was ""

This commit is contained in:
nathan 2022-02-17 10:30:35 -07:00
parent be4633c9fa
commit b8455e0b8d

View File

@ -44,23 +44,27 @@ export class Et2DateTimeOnly extends Et2DateTime
set_value(value) set_value(value)
{ {
let adjustedValue : Date | string = '';
if(!value || value == 0 || value == "0") if(!value || value == 0 || value == "0")
{ {
value = ''; value = '';
} }
// Handle timezone offset, flatpickr uses local time // Handle timezone offset, flatpickr uses local time
let date = new Date(value); if(value)
let formatDate = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000); {
formatDate.setDate(1); let date = new Date(value);
formatDate.setMonth(0) adjustedValue = new Date(date.valueOf() + date.getTimezoneOffset() * 60 * 1000);
formatDate.setFullYear(1970); adjustedValue.setDate(1);
adjustedValue.setMonth(0)
adjustedValue.setFullYear(1970);
}
if(!this._instance) if(!this._instance)
{ {
this.defaultDate = formatDate; this.defaultDate = adjustedValue;
} }
else else
{ {
this.setDate(formatDate); this.setDate(adjustedValue);
} }
} }
} }