mirror of
https://github.com/MetaFam/TheGame.git
synced 2026-02-08 21:15:05 -05:00
36 lines
977 B
TypeScript
36 lines
977 B
TypeScript
import { PlayerFragmentFragment } from "graphql/autogen/types";
|
|
import spacetime from 'spacetime';
|
|
import { display } from 'spacetime-informal';
|
|
|
|
export interface TimeZoneDisplay {
|
|
timeZone?: string;
|
|
offset?: string;
|
|
}
|
|
|
|
export const getPlayerTimeZoneDisplay = (player: PlayerFragmentFragment): TimeZoneDisplay => {
|
|
let tzLabel;
|
|
let offsetLabel;
|
|
if (player?.timezone) {
|
|
const timeZone = spacetime.now().goto(player.timezone)
|
|
const tzDisplay = display(player.timezone)
|
|
if (tzDisplay && tzDisplay.daylight && tzDisplay.standard) {
|
|
tzLabel = timeZone.isDST()
|
|
? tzDisplay.daylight.abbrev
|
|
: tzDisplay.standard.abbrev;
|
|
const {offset} = timeZone.timezone().current;
|
|
if (offset > 0) {
|
|
offsetLabel = `(GMT +${offset})`;
|
|
} else if (offset < 0) {
|
|
offsetLabel = `(GMT ${offset})`;
|
|
}
|
|
} else {
|
|
tzLabel = player.timezone;
|
|
}
|
|
}
|
|
|
|
return {
|
|
timeZone: tzLabel,
|
|
offset: offsetLabel
|
|
}
|
|
}
|
|
|