mirror of
https://github.com/immich-app/immich.git
synced 2024-12-29 07:01: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:
parent
cbb0a7f8d4
commit
4bf82fb4c4
1 changed files with 16 additions and 7 deletions
|
@ -10,18 +10,25 @@
|
||||||
|
|
||||||
type ZoneOption = {
|
type ZoneOption = {
|
||||||
/**
|
/**
|
||||||
* Timezone name
|
* Timezone name with offset
|
||||||
*
|
*
|
||||||
* e.g. Asia/Jerusalem (+03:00)
|
* e.g. Asia/Jerusalem (+03:00)
|
||||||
*/
|
*/
|
||||||
label: string;
|
label: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Timezone offset
|
* Timezone name
|
||||||
*
|
*
|
||||||
* e.g. UTC+01:00
|
* e.g. Asia/Jerusalem
|
||||||
*/
|
*/
|
||||||
value: string;
|
value: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Timezone offset in minutes
|
||||||
|
*
|
||||||
|
* e.g. 300
|
||||||
|
*/
|
||||||
|
offsetMinutes: number;
|
||||||
};
|
};
|
||||||
|
|
||||||
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
|
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
|
||||||
|
@ -37,21 +44,23 @@
|
||||||
const offset = zone.toFormat('ZZ');
|
const offset = zone.toFormat('ZZ');
|
||||||
return {
|
return {
|
||||||
label: `${zone.zoneName} (${offset})`,
|
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 && {
|
let selectedOption = initialOption && {
|
||||||
label: initialOption?.label || '',
|
label: initialOption?.label || '',
|
||||||
|
offsetMinutes: initialOption?.offsetMinutes || 0,
|
||||||
value: initialOption?.value || '',
|
value: initialOption?.value || '',
|
||||||
};
|
};
|
||||||
|
|
||||||
let selectedDate = initialDate.toFormat("yyyy-MM-dd'T'HH:mm");
|
let selectedDate = initialDate.toFormat("yyyy-MM-dd'T'HH:mm");
|
||||||
|
|
||||||
// Keep local time if not it's really confusing
|
// when changing the time zone, assume the configured date/time is meant for that time zone (instead of updating it)
|
||||||
$: date = DateTime.fromISO(selectedDate).setZone(selectedOption?.value, { keepLocalTime: true });
|
$: date = DateTime.fromISO(selectedDate, { zone: selectedOption?.value, setZone: true });
|
||||||
|
|
||||||
const dispatch = createEventDispatcher<{
|
const dispatch = createEventDispatcher<{
|
||||||
cancel: void;
|
cancel: void;
|
||||||
|
|
Loading…
Reference in a new issue