Skip to content

Commit

Permalink
refactor: include timezone in toLocaleTimeString
Browse files Browse the repository at this point in the history
  • Loading branch information
alee committed Oct 27, 2023
1 parent 7e73a78 commit ca9951b
Showing 1 changed file with 9 additions and 15 deletions.
24 changes: 9 additions & 15 deletions client/src/components/global/Schedule.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
:key="game.date.getTime()"
>
<div class="launch-date">
<b>{{ formatTime(game.date) }}</b> ({{ localTimeZone }})
<b>{{ formatTime(game.date) }}</b>
</div>
<b-button-group>
<a
Expand Down Expand Up @@ -56,25 +56,18 @@ export default class Schedule extends Vue {
@Prop()
schedule!: Array<number>;
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<string, object> 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",
Expand All @@ -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"],
});
Expand All @@ -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",
});
}
}
Expand Down

0 comments on commit ca9951b

Please sign in to comment.