From 1d282851e275a564981cced0d141e5b65f08871e Mon Sep 17 00:00:00 2001 From: daniel bogachevsky <80171988+WazWazTheDeveloper@users.noreply.github.com> Date: Mon, 1 Jul 2024 06:41:47 +0300 Subject: [PATCH] fix(web): Sort timezones in assets settings by offset (#10697) * fixed timezones on web are sorted alphabetically * swaped order of operations in order to use DataTime.offset property for sorting * optimization --- .../shared-components/change-date.svelte | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/web/src/lib/components/shared-components/change-date.svelte b/web/src/lib/components/shared-components/change-date.svelte index 4b2f02f86d..970280736e 100644 --- a/web/src/lib/components/shared-components/change-date.svelte +++ b/web/src/lib/components/shared-components/change-date.svelte @@ -12,7 +12,7 @@ /** * Timezone name * - * e.g. Europe/Berlin + * e.g. Asia/Jerusalem (+03:00) */ label: string; @@ -24,10 +24,22 @@ value: string; }; - const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone').map((zone: string) => ({ - label: zone + ` (${DateTime.local({ zone }).toFormat('ZZ')})`, - value: 'UTC' + DateTime.local({ zone }).toFormat('ZZ'), - })); + 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, + }; + }); const initialOption = timezones.find((item) => item.value === 'UTC' + initialDate.toFormat('ZZ'));