mirror of
https://github.com/immich-app/immich.git
synced 2025-12-05 20:40:29 -08:00
fix(web): fix timezone dropdown for timestamps lacking milliseconds (#23615)
Fix timezone selector for timestamps without milliseconds
This commit is contained in:
@@ -70,9 +70,14 @@ export function getModernOffsetForZoneAndDate(
|
|||||||
|
|
||||||
function zoneOptionForDate(zone: string, date: string) {
|
function zoneOptionForDate(zone: string, date: string) {
|
||||||
const { offsetMinutes, offsetFormat: zoneOffsetAtDate } = getModernOffsetForZoneAndDate(zone, date);
|
const { offsetMinutes, offsetFormat: zoneOffsetAtDate } = getModernOffsetForZoneAndDate(zone, date);
|
||||||
// For validity, we still need to check if the exact date/time exists in the *original* timezone (for gaps/overlaps).
|
// For validity, we still need to check if the exact date/time exists in the *original* timezone.
|
||||||
const dateForValidity = DateTime.fromISO(date, { zone });
|
// Use the fact that in DST gaps Luxon advances the missing time by an hour.
|
||||||
const valid = dateForValidity.isValid && date === dateForValidity.toFormat("yyyy-MM-dd'T'HH:mm:ss.SSS");
|
// Ignore milliseconds:
|
||||||
|
// - milliseconds are not relevant for TZ calculations
|
||||||
|
// - browsers strip insignificant .000 making string comparison with milliseconds more fragile.
|
||||||
|
const dateInTimezone = DateTime.fromISO(date, { zone });
|
||||||
|
const exists = date.replace(/\.\d+/, '') === dateInTimezone.toFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
const valid = dateInTimezone.isValid && exists;
|
||||||
return {
|
return {
|
||||||
value: zone,
|
value: zone,
|
||||||
offsetMinutes,
|
offsetMinutes,
|
||||||
|
|||||||
Reference in New Issue
Block a user