diff --git a/src/core/features/user/pages/about/about.ts b/src/core/features/user/pages/about/about.ts index 64671bcccf9..5960629d36d 100644 --- a/src/core/features/user/pages/about/about.ts +++ b/src/core/features/user/pages/about/about.ts @@ -120,11 +120,7 @@ export class CoreUserAboutPage implements OnInit, OnDestroy { this.user.address = CoreUserHelper.formatAddress('', user.city, user.country); - const serverTimezone = CoreSites.getCurrentSite()?.getStoredConfig('timezone'); - this.displayTimezone = !!serverTimezone; - if (this.displayTimezone && this.user.timezone === USER_PROFILE_SERVER_TIMEZONE) { - this.user.timezone = serverTimezone; - } + this.fillTimezone(); await this.checkUserImageUpdated(); } catch (error) { @@ -261,6 +257,30 @@ export class CoreUserAboutPage implements OnInit, OnDestroy { return avatarUrl; } + /** + * Fill user timezone depending on the server and fix the legacy timezones. + */ + protected fillTimezone(): void { + if (!this.user) { + return; + } + + const serverTimezone = CoreSites.getCurrentSite()?.getStoredConfig('timezone'); + this.displayTimezone = !!serverTimezone; + + if (!this.displayTimezone) { + return; + } + + if (this.user.timezone === USER_PROFILE_SERVER_TIMEZONE) { + this.user.timezone = serverTimezone; + } + + if (this.user.timezone) { + this.user.timezone = this.getLegacyTimezone(this.user.timezone); + } + } + /** * Open a user interest. * @@ -279,4 +299,72 @@ export class CoreUserAboutPage implements OnInit, OnDestroy { this.obsProfileRefreshed?.off(); } + /** + * Translates legacy timezone names. + * + * @param tz Timezone name. + * @returns Readable timezone name. + */ + protected getLegacyTimezone(tz: string): string { + const legacyTzs = { + '': 'Australia/Perth', // Fallback on default timezone. + '-13.0': 'Australia/Perth', // Fallback on default timezone. + '-12.5': 'Etc/GMT+12', + '-12.0': 'Etc/GMT+12', + '-11.5': 'Etc/GMT+11', + '-11.0': 'Etc/GMT+11', + '-10.5': 'Etc/GMT+10', + '-10.0': 'Etc/GMT+10', + '-9.5': 'Etc/GMT+9', + '-9.0': 'Etc/GMT+9', + '-8.5': 'Etc/GMT+8', + '-8.0': 'Etc/GMT+8', + '-7.5': 'Etc/GMT+7', + '-7.0': 'Etc/GMT+7', + '-6.5': 'Etc/GMT+6', + '-6.0': 'Etc/GMT+6', + '-5.5': 'Etc/GMT+5', + '-5.0': 'Etc/GMT+5', + '-4.5': 'Etc/GMT+4', + '-4.0': 'Etc/GMT+4', + '-3.5': 'Etc/GMT+3', + '-3.0': 'Etc/GMT+3', + '-2.5': 'Etc/GMT+2', + '-2.0': 'Etc/GMT+2', + '-1.5': 'Etc/GMT+1', + '-1.0': 'Etc/GMT+1', + '-0.5': 'Etc/GMT', + '0': 'Etc/GMT', + '0.0': 'Etc/GMT', + '0.5': 'Etc/GMT', + '1.0': 'Etc/GMT-1', + '1.5': 'Etc/GMT-1', + '2.0': 'Etc/GMT-2', + '2.5': 'Etc/GMT-2', + '3.0': 'Etc/GMT-3', + '3.5': 'Etc/GMT-3', + '4.0': 'Etc/GMT-4', + '4.5': 'Asia/Kabul', + '5.0': 'Etc/GMT-5', + '5.5': 'Asia/Kolkata', + '6.0': 'Etc/GMT-6', + '6.5': 'Asia/Rangoon', + '7.0': 'Etc/GMT-7', + '7.5': 'Etc/GMT-7', + '8.0': 'Etc/GMT-8', + '8.5': 'Etc/GMT-8', + '9.0': 'Etc/GMT-9', + '9.5': 'Australia/Darwin', + '10.0': 'Etc/GMT-10', + '10.5': 'Etc/GMT-10', + '11.0': 'Etc/GMT-11', + '11.5': 'Etc/GMT-11', + '12.0': 'Etc/GMT-12', + '12.5': 'Etc/GMT-12', + '13.0': 'Etc/GMT-13', + }; + + return legacyTzs[tz] ?? tz; + } + }