mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-11 06:24:56 -05:00
33 lines
766 B
TypeScript
33 lines
766 B
TypeScript
import { TimezoneOptions } from '@metafam/ds';
|
|
import { PlayerFragmentFragment } from 'graphql/autogen/types';
|
|
|
|
export interface TimeZoneDisplay {
|
|
timeZone?: string;
|
|
offset?: string;
|
|
}
|
|
|
|
export const getPlayerTimeZoneDisplay = (
|
|
player: PlayerFragmentFragment,
|
|
): TimeZoneDisplay => {
|
|
let tzLabel;
|
|
let offsetLabel;
|
|
const timezone = TimezoneOptions.find((t) => t.value === player?.timezone);
|
|
if (timezone) {
|
|
const { abbrev, offset, value } = timezone;
|
|
tzLabel = value;
|
|
if (abbrev.length < 5) {
|
|
tzLabel = abbrev;
|
|
if (offset > 0) {
|
|
offsetLabel = `(GMT +${offset})`;
|
|
} else if (offset < 0) {
|
|
offsetLabel = `(GMT ${offset})`;
|
|
}
|
|
}
|
|
}
|
|
|
|
return {
|
|
timeZone: tzLabel,
|
|
offset: offsetLabel,
|
|
};
|
|
};
|