-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(web): Sort timezones in assets settings by offset #10697
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One unnecessary nitpick, but looks good. Thanks!
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone') | ||
.sort((zoneA, zoneB) => { | ||
let numericallyCorrect = DateTime.local({ zone: zoneA }).offset - DateTime.local({ zone: zoneB }).offset; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You could do something like this so you're only calling DateTime.local()
once:
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
.map((zone) => DateTime.local(zone))
.sort((zoneA, zoneB) => {
let numericallyCorrect = zoneA.offset - zoneB.offset;
...etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But you will have to pass the zone string for the creation of the list items in the last .map
so it will be something more like this
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
.map((zone) => ({
datatime: DateTime.local({ zone }),
string: zone,
}))
.sort((zoneA, zoneB) => {
let numericallyCorrect = zoneA.datatime.offset - zoneB.datatime.offset;
if (numericallyCorrect != 0) {
return numericallyCorrect;
}
const alphabeticallyCorrect = zoneA.string.localeCompare(zoneB.string, undefined, { sensitivity: 'base' });
return alphabeticallyCorrect;
})
.map((zone) => ({
label: zone.string + ` (${DateTime.local({ zone: zone.string }).toFormat('ZZ')})`,
value: 'UTC' + DateTime.local({ zone: zone.string }).toFormat('ZZ'),
}));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DateTime.zoneName
can be used:
const timezones: ZoneOption[] = Intl.supportedValuesOf('timeZone')
.map((zone) => DateTime.local({ zone }))
.sort((a, b) => a.offset - b.offset || a.zoneName.localeCompare(b.zoneName, undefined, { sensitivity: 'base' }))
.map((date) => {
const offset = date.toFormat('ZZ');
return {
label: `${date.zoneName} (${offset})`,
value: 'UTC' + offset,
};
});
Hello, can you add a unit test for this mechanism? Thank you for the contribution! |
fixes #10695