From ca9951bccb98d3f12f8a93d89309d89ece020173 Mon Sep 17 00:00:00 2001 From: Allen Lee Date: Fri, 27 Oct 2023 16:53:57 -0700 Subject: [PATCH] refactor: include timezone in toLocaleTimeString --- client/src/components/global/Schedule.vue | 24 +++++++++-------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/client/src/components/global/Schedule.vue b/client/src/components/global/Schedule.vue index bb97fdc62..1130dadfe 100644 --- a/client/src/components/global/Schedule.vue +++ b/client/src/components/global/Schedule.vue @@ -11,7 +11,7 @@ :key="game.date.getTime()" >
- {{ formatTime(game.date) }} ({{ localTimeZone }}) + {{ formatTime(game.date) }}
; - readonly SITE_URL = "https://portofmars.asu.edu"; + static readonly SITE_URL = "https://portofmars.asu.edu"; get launchTimes() { return this.groupLaunchTimesByDate(this.schedule); } - get localTimeZone() { - return new Date() - .toLocaleTimeString(undefined, { - timeZoneName: "short", - }) - .split(" ")[2]; - } - groupLaunchTimesByDate(launchTimes: number[]) { - // returns an object with date strings mapped to indivual launch times and invite links + // returns an object with date strings mapped to individual launch times and invite links + // could use a Map also const grouped: LaunchTimes = {}; for (const time of launchTimes) { - const dateStr = new Date(time).toLocaleDateString(undefined, { + const dateStr = new Date(time).toLocaleDateString([], { weekday: "long", month: "long", day: "numeric", @@ -96,7 +89,7 @@ export default class Schedule extends Vue { buildGoogleInviteLink(start: Date) { return google({ title: `Port of Mars Launch`, - location: this.SITE_URL, + location: Schedule.SITE_URL, start, duration: [1, "hour"], }); @@ -105,16 +98,17 @@ export default class Schedule extends Vue { buildIcsInviteLink(start: Date) { return ics({ title: `Port of Mars Launch`, - location: this.SITE_URL, + location: Schedule.SITE_URL, start, duration: [1, "hour"], }); } formatTime(date: Date) { - return date.toLocaleTimeString(undefined, { + return date.toLocaleTimeString([], { hour: "numeric", minute: "numeric", + timeZoneName: "short", }); } }