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:
Simon Larsen
2024-06-17 16:23:49 +01:00
parent c4e4e7e488
commit 3573e59634

View File

@@ -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 {