mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-11 02:13:48 +00:00
refactor: add timezone data to session
This commit is contained in:
committed by
Carlos Valente
parent
50ebcf4e14
commit
4a6fbc2a92
@@ -1,5 +1,4 @@
|
||||
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND, parseUserTime } from 'ontime-utils';
|
||||
import { isISO8601 } from '../../../../packages/utils/src/date-utils/isTimeString.js';
|
||||
import { MILLIS_PER_HOUR, MILLIS_PER_MINUTE, MILLIS_PER_SECOND, pad, parseUserTime, isISO8601 } from 'ontime-utils';
|
||||
|
||||
export const timeFormat = 'HH:mm';
|
||||
export const timeFormatSeconds = 'HH:mm:ss';
|
||||
@@ -46,3 +45,18 @@ export function parseExcelDate(excelDate: unknown): number {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
export function getTimezoneLabel(date: Date): string {
|
||||
const tz = date.getTimezoneOffset();
|
||||
const tzName = Intl.DateTimeFormat().resolvedOptions().timeZone;
|
||||
|
||||
// timezone offset is inverted
|
||||
const sign = tz < 0 ? '+' : '-';
|
||||
const abs = Math.abs(tz);
|
||||
|
||||
// convert minutes to hours
|
||||
const hours = Math.floor(abs / 60);
|
||||
const minutes = abs % 60;
|
||||
|
||||
return `GMT ${sign}${pad(hours)}:${pad(minutes)} ${tzName}`;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user