mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-07-28 01:09:37 +02:00
Validate ISO date in toLocalDatetime function and return empty string for invalid dates
This commit is contained in:
parent
c9fa1d55f7
commit
8538aa0b7c
1 changed files with 9 additions and 3 deletions
|
@ -12,9 +12,15 @@ export function toLocalDatetime(
|
||||||
timezone: string = Intl.DateTimeFormat().resolvedOptions().timeZone
|
timezone: string = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||||
): string {
|
): string {
|
||||||
if (!utcDate) return '';
|
if (!utcDate) return '';
|
||||||
const isoString = DateTime.fromISO(utcDate, { zone: 'UTC' })
|
|
||||||
.setZone(timezone)
|
const dt = DateTime.fromISO(utcDate, { zone: 'UTC' });
|
||||||
.toISO({ suppressSeconds: true, includeOffset: false });
|
if (!dt.isValid) return '';
|
||||||
|
|
||||||
|
const isoString = dt.setZone(timezone).toISO({
|
||||||
|
suppressSeconds: true,
|
||||||
|
includeOffset: false
|
||||||
|
});
|
||||||
|
|
||||||
return isoString ? isoString.slice(0, 16) : '';
|
return isoString ? isoString.slice(0, 16) : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue