Skip to content

Commit

Permalink
MOBILE-4362 user: Fix timezone names
Browse files Browse the repository at this point in the history
  • Loading branch information
crazyserver committed Oct 5, 2023
1 parent 7873205 commit 9f8d0ef
Showing 1 changed file with 93 additions and 5 deletions.
98 changes: 93 additions & 5 deletions src/core/features/user/pages/about/about.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}

}

0 comments on commit 9f8d0ef

Please sign in to comment.