Files
oneuptime/Common/UI/Utils/Timezone.ts
Simon Larsen 714823514c Refactor import paths in test and UI component files for consistency
- Updated import statements in various test files to use relative paths instead of absolute paths.
- Adjusted import paths in UI components to ensure they correctly reference the Types and Models directories.
- Ensured all components and tests are aligned with the new directory structure for better maintainability.
2025-05-21 16:19:35 +01:00

38 lines
1.2 KiB
TypeScript

import Timezone from "../../Types/Timezone";
import { DropdownOption } from "../Components/Dropdown/Dropdown";
import OneUptimeDate from "../../Types/Date";
export default class TimezoneUtil {
public static getTimezoneDropdownOptions(): DropdownOption[] {
let timezoneOptions: Array<string> = Object.keys(Timezone);
// order timezone by GMT offset.
timezoneOptions = timezoneOptions.sort((a: string, b: string) => {
const keyOfTimezoneA: keyof typeof Timezone = a as keyof typeof Timezone;
const keyOfTimezoneB: keyof typeof Timezone = b as keyof typeof Timezone;
return (
OneUptimeDate.getGmtOffsetByTimezone(Timezone[keyOfTimezoneA]) -
OneUptimeDate.getGmtOffsetByTimezone(Timezone[keyOfTimezoneB])
);
});
return timezoneOptions.map((key: string) => {
const keyOfTimezone: keyof typeof Timezone = key as keyof typeof Timezone;
const value: string =
Timezone && Timezone[keyOfTimezone]
? Timezone[keyOfTimezone].toString()
: "";
return {
value: value,
label: OneUptimeDate.getGmtOffsetFriendlyStringByTimezone(
Timezone[keyOfTimezone],
),
};
});
}
}