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 6, 2023
1 parent b39bd13 commit 4cee48f
Show file tree
Hide file tree
Showing 2 changed files with 92 additions and 5 deletions.
30 changes: 25 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.getRequiredCurrentSite().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 = CoreUserHelper.translateLegacyTimezone(this.user.timezone);
}
}

/**
* Open a user interest.
*
Expand Down
67 changes: 67 additions & 0 deletions src/core/features/user/services/user-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,63 @@ import { CoreUserProfile, CoreUserRole } from './user';
@Injectable({ providedIn: 'root' })
export class CoreUserHelperProvider {

protected static readonly LEGACY_TIMEZONES = {
'-13.0': 'Australia/Perth',
'-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',
};

/**
* Formats a user address, concatenating address, city and country.
*
Expand Down Expand Up @@ -98,6 +155,16 @@ export class CoreUserHelperProvider {
return (user.firstname?.charAt(0) || '') + (user.lastname?.charAt(0) || '');
}

/**
* Translates legacy timezone names.
*
* @param tz Timezone name.
* @returns Readable timezone name.
*/
translateLegacyTimezone(tz: string): string {
return CoreUserHelperProvider.LEGACY_TIMEZONES[tz] ?? tz;
}

}

export const CoreUserHelper = makeSingleton(CoreUserHelperProvider);

0 comments on commit 4cee48f

Please sign in to comment.