FIX: prevents timezone to show duplicated zones in preview

It could happen if you have Etc/UTC in default settings, and timezone="UTC" on date, the equality check is now more strict.
This commit is contained in:
Joffrey JAFFEUX 2019-11-22 17:14:27 +01:00 committed by GitHub
parent 2c335efd1e
commit a40bc1e92b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 18 deletions

View File

@ -125,6 +125,10 @@
}
function _isEqualZones(timezoneA, timezoneB) {
if (timezoneA.includes(timezoneB) || timezoneB.includes(timezoneA)) {
return true;
}
return (
moment.tz(timezoneA).utcOffset() === moment.tz(timezoneB).utcOffset()
);
@ -222,7 +226,9 @@
const previewedTimezones = [];
const watchingUserTimezone = moment.tz.guess();
const timezones = options.timezones.filter(
timezone => timezone !== watchingUserTimezone
timezone =>
!_isEqualZones(timezone, watchingUserTimezone) &&
!_isEqualZones(timezone, options.timezone)
);
previewedTimezones.push({
@ -244,26 +250,24 @@
timezones.unshift(options.timezone);
}
timezones
.filter(z => z)
.forEach(timezone => {
if (_isEqualZones(timezone, displayedTimezone)) {
return;
}
timezones.filter(Boolean).forEach(timezone => {
if (_isEqualZones(timezone, displayedTimezone)) {
return;
}
if (_isEqualZones(timezone, watchingUserTimezone)) {
timezone = watchingUserTimezone;
}
if (_isEqualZones(timezone, watchingUserTimezone)) {
timezone = watchingUserTimezone;
}
previewedTimezones.push({
timezone,
dateTime: options.time
? moment(dateTime)
.tz(timezone)
.format("LLL")
: _createDateTimeRange(dateTime, timezone)
});
previewedTimezones.push({
timezone,
dateTime: options.time
? moment(dateTime)
.tz(timezone)
.format("LLL")
: _createDateTimeRange(dateTime, timezone)
});
});
if (!previewedTimezones.length) {
previewedTimezones.push({