2023-11-30 04:52:28 +01:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { createEventDispatcher } from 'svelte';
|
|
|
|
|
import { DateTime } from 'luxon';
|
2024-05-28 09:10:43 +07:00
|
|
|
import ConfirmDialog from './dialog/confirm-dialog.svelte';
|
2024-01-27 11:36:40 -07:00
|
|
|
import Combobox from './combobox.svelte';
|
2024-02-27 04:07:49 +01:00
|
|
|
import DateInput from '../elements/date-input.svelte';
|
2024-06-04 21:53:00 +02:00
|
|
|
import { t } from 'svelte-i18n';
|
2024-02-22 15:36:14 +01:00
|
|
|
|
2023-11-30 04:52:28 +01:00
|
|
|
export let initialDate: DateTime = DateTime.now();
|
|
|
|
|
|
2024-01-27 11:36:40 -07:00
|
|
|
type ZoneOption = {
|
|
|
|
|
/**
|
|
|
|
|
* Timezone name
|
|
|
|
|
*
|
2024-07-01 06:41:47 +03:00
|
|
|
* e.g. Asia/Jerusalem (+03:00)
|
2024-01-27 11:36:40 -07:00
|
|
|
*/
|
|
|
|
|
label: string;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Timezone offset
|
|
|
|
|
*
|
|
|
|
|
* e.g. UTC+01:00
|
|
|
|
|
*/
|
|
|
|
|
value: string;
|
|
|
|
|
};
|
2023-11-30 04:52:28 +01:00
|
|
|
|
2024-07-01 06:41:47 +03:00
|
|
|
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
|
|
|
|
|
.map((zone) => DateTime.local({ zone }))
|
|
|
|
|
.sort((zoneA, zoneB) => {
|
|
|
|
|
let numericallyCorrect = zoneA.offset - zoneB.offset;
|
|
|
|
|
if (numericallyCorrect != 0) {
|
|
|
|
|
return numericallyCorrect;
|
|
|
|
|
}
|
|
|
|
|
return zoneA.zoneName.localeCompare(zoneB.zoneName, undefined, { sensitivity: 'base' });
|
|
|
|
|
})
|
|
|
|
|
.map((zone) => {
|
|
|
|
|
const offset = zone.toFormat('ZZ');
|
|
|
|
|
return {
|
|
|
|
|
label: `${zone.zoneName} (${offset})`,
|
|
|
|
|
value: 'UTC' + offset,
|
|
|
|
|
};
|
|
|
|
|
});
|
2023-11-30 04:52:28 +01:00
|
|
|
|
2024-01-27 11:36:40 -07:00
|
|
|
const initialOption = timezones.find((item) => item.value === 'UTC' + initialDate.toFormat('ZZ'));
|
2023-11-30 04:52:28 +01:00
|
|
|
|
2024-02-22 14:12:33 +01:00
|
|
|
let selectedOption = initialOption && {
|
2024-01-27 11:36:40 -07:00
|
|
|
label: initialOption?.label || '',
|
|
|
|
|
value: initialOption?.value || '',
|
2023-11-30 04:52:28 +01:00
|
|
|
};
|
|
|
|
|
|
2024-01-27 11:36:40 -07:00
|
|
|
let selectedDate = initialDate.toFormat("yyyy-MM-dd'T'HH:mm");
|
2024-02-17 15:28:34 +01:00
|
|
|
|
|
|
|
|
// Keep local time if not it's really confusing
|
2024-02-22 14:12:33 +01:00
|
|
|
$: date = DateTime.fromISO(selectedDate).setZone(selectedOption?.value, { keepLocalTime: true });
|
2023-11-30 04:52:28 +01:00
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher<{
|
|
|
|
|
cancel: void;
|
|
|
|
|
confirm: string;
|
|
|
|
|
}>();
|
|
|
|
|
|
|
|
|
|
const handleCancel = () => dispatch('cancel');
|
2024-01-27 11:36:40 -07:00
|
|
|
|
2023-11-30 04:52:28 +01:00
|
|
|
const handleConfirm = () => {
|
|
|
|
|
const value = date.toISO();
|
|
|
|
|
if (value) {
|
|
|
|
|
dispatch('confirm', value);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
</script>
|
|
|
|
|
|
2024-05-28 09:10:43 +07:00
|
|
|
<ConfirmDialog
|
2024-04-30 06:59:32 +09:00
|
|
|
confirmColor="primary"
|
2024-06-04 21:53:00 +02:00
|
|
|
title={$t('edit_date_and_time')}
|
2024-04-30 06:59:32 +09:00
|
|
|
prompt="Please select a new date:"
|
|
|
|
|
disabled={!date.isValid}
|
|
|
|
|
onConfirm={handleConfirm}
|
2024-05-28 09:10:43 +07:00
|
|
|
onCancel={handleCancel}
|
2024-04-30 06:59:32 +09:00
|
|
|
>
|
|
|
|
|
<div class="flex flex-col text-md px-4 text-center gap-2" slot="prompt">
|
|
|
|
|
<div class="flex flex-col">
|
2024-06-04 21:53:00 +02:00
|
|
|
<label for="datetime">{$t('date_and_time')}</label>
|
2024-04-30 06:59:32 +09:00
|
|
|
<DateInput
|
|
|
|
|
class="immich-form-input text-sm my-4 w-full"
|
|
|
|
|
id="datetime"
|
|
|
|
|
type="datetime-local"
|
|
|
|
|
bind:value={selectedDate}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="flex flex-col w-full mt-2">
|
2024-06-04 21:53:00 +02:00
|
|
|
<Combobox bind:selectedOption label={$t('timezone')} options={timezones} placeholder={$t('search_timezone')} />
|
2023-11-30 04:52:28 +01:00
|
|
|
</div>
|
2024-04-30 06:59:32 +09:00
|
|
|
</div>
|
2024-05-28 09:10:43 +07:00
|
|
|
</ConfirmDialog>
|