1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2024-12-28 22:51:59 +00:00

fix(web): retain selected time zone offset also for +00:00 (#12310)

Co-authored-by: Alex <alex.tran1502@gmail.com>
This commit is contained in:
Carsten Otto 2024-09-04 16:47:40 +02:00 committed by GitHub
parent cbb0a7f8d4
commit 4bf82fb4c4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -10,18 +10,25 @@
type ZoneOption = {
/**
* Timezone name
* Timezone name with offset
*
* e.g. Asia/Jerusalem (+03:00)
*/
label: string;
/**
* Timezone offset
* Timezone name
*
* e.g. UTC+01:00
* e.g. Asia/Jerusalem
*/
value: string;
/**
* Timezone offset in minutes
*
* e.g. 300
*/
offsetMinutes: number;
};
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
@ -37,21 +44,23 @@
const offset = zone.toFormat('ZZ');
return {
label: `${zone.zoneName} (${offset})`,
value: 'UTC' + offset,
value: zone.zoneName,
offsetMinutes: zone.offset,
};
});
const initialOption = timezones.find((item) => item.value === 'UTC' + initialDate.toFormat('ZZ'));
const initialOption = timezones.find((item) => item.offsetMinutes === initialDate.offset);
let selectedOption = initialOption && {
label: initialOption?.label || '',
offsetMinutes: initialOption?.offsetMinutes || 0,
value: initialOption?.value || '',
};
let selectedDate = initialDate.toFormat("yyyy-MM-dd'T'HH:mm");
// Keep local time if not it's really confusing
$: date = DateTime.fromISO(selectedDate).setZone(selectedOption?.value, { keepLocalTime: true });
// when changing the time zone, assume the configured date/time is meant for that time zone (instead of updating it)
$: date = DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true });
const dispatch = createEventDispatcher<{
cancel: void;