chore: ensure timezones uniqueness in time-between-dates

This commit is contained in:
Ibrahima G. Coulibaly
2025-04-10 16:56:51 +01:00
parent ba47687546
commit c8a320cf18

View File

@@ -50,8 +50,9 @@ const validationSchema = Yup.object({
const timezoneOptions = [
{ value: 'local', label: 'Local Time' },
...Intl.supportedValuesOf('timeZone')
.map((tz) => {
...Array.from(
new Map(
Intl.supportedValuesOf('timeZone').map((tz) => {
const formatter = new Intl.DateTimeFormat('en', {
timeZone: tz,
timeZoneName: 'shortOffset'
@@ -62,14 +63,18 @@ const timezoneOptions = [
.formatToParts(new Date())
.find((part) => part.type === 'timeZoneName')?.value || '';
return {
value: offset.replace('UTC', 'GMT'),
label: `${offset.replace('UTC', 'GMT')} (${tz})`
};
const value = offset.replace('UTC', 'GMT');
return [
value, // key for Map to ensure uniqueness
{
value,
label: `${value} (${tz})`
}
];
})
.sort((a, b) =>
a.value.localeCompare(b.value, undefined, { numeric: true })
)
).values()
).sort((a, b) => a.value.localeCompare(b.value, undefined, { numeric: true }))
];
const exampleCards: CardExampleType<InitialValuesType>[] = [