Computer Science Club of the University of Waterloo's website.
https://csclub.uwaterloo.ca
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
23 lines
749 B
23 lines
749 B
import { utcToZonedTime, zonedTimeToUtc } from "date-fns-tz";
|
|
|
|
export const TERMS = ["winter", "spring", "fall"] as const;
|
|
export type Term = typeof TERMS[number];
|
|
export const DATE_FORMAT = "MMMM dd yyyy HH:mm";
|
|
|
|
// https://www.typescriptlang.org/docs/handbook/2/narrowing.html#using-type-predicates
|
|
export function isTerm(x: string): x is Term {
|
|
return TERMS.some((term) => x === term);
|
|
}
|
|
|
|
export function capitalize(str: string) {
|
|
return str.slice(0, 1).toUpperCase() + str.slice(1);
|
|
}
|
|
|
|
// Converts a date to local time
|
|
export function getLocalDateFromEST(date: Date): Date {
|
|
return utcToZonedTime(
|
|
// The date parameter is in EST
|
|
zonedTimeToUtc(date, "America/Toronto"),
|
|
Intl.DateTimeFormat().resolvedOptions().timeZone
|
|
);
|
|
}
|
|
|