mirror of
https://github.com/seanmorley15/AdventureLog.git
synced 2025-12-23 22:58:17 -05:00
Validate ISO date in toLocalDatetime function and return empty string for invalid dates
This commit is contained in:
@@ -12,9 +12,15 @@ export function toLocalDatetime(
|
||||
timezone: string = Intl.DateTimeFormat().resolvedOptions().timeZone
|
||||
): string {
|
||||
if (!utcDate) return '';
|
||||
const isoString = DateTime.fromISO(utcDate, { zone: 'UTC' })
|
||||
.setZone(timezone)
|
||||
.toISO({ suppressSeconds: true, includeOffset: false });
|
||||
|
||||
const dt = DateTime.fromISO(utcDate, { zone: 'UTC' });
|
||||
if (!dt.isValid) return '';
|
||||
|
||||
const isoString = dt.setZone(timezone).toISO({
|
||||
suppressSeconds: true,
|
||||
includeOffset: false
|
||||
});
|
||||
|
||||
return isoString ? isoString.slice(0, 16) : '';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user