mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
refactor: Update getCurrentTimezoneString method in Date.ts
This commit refactors the getCurrentTimezoneString method in the Date.ts file. It replaces the usage of moment.tz.guess() with this.getCurrentTimezone() to improve code readability and maintainability. Additionally, it adds a check to prepend "GMT" to the zone abbreviation if it starts with a "+" or "-" sign. This change ensures consistent formatting of the timezone string returned by the method.
This commit is contained in:
@@ -1008,11 +1008,17 @@ export default class OneUptimeDate {
|
||||
}
|
||||
|
||||
public static getCurrentTimezoneString(): string {
|
||||
return moment.tz(moment.tz.guess()).zoneAbbr() as Timezone;
|
||||
return this.getZoneAbbrByTimezone(this.getCurrentTimezone());
|
||||
}
|
||||
|
||||
public static getZoneAbbrByTimezone(timezone: Timezone): string {
|
||||
return moment.tz(timezone).zoneAbbr();
|
||||
let zoneAbbr = moment.tz(timezone).zoneAbbr();
|
||||
|
||||
if(zoneAbbr.startsWith('+') || zoneAbbr.startsWith('-')) {
|
||||
zoneAbbr = 'GMT' + zoneAbbr;
|
||||
}
|
||||
|
||||
return zoneAbbr;
|
||||
}
|
||||
|
||||
public static getCurrentTimezone(): Timezone {
|
||||
|
||||
Reference in New Issue
Block a user