From 1ad8ac040d87af3776b2b0954c01312111eb03ec Mon Sep 17 00:00:00 2001 From: Matt Isenhower Date: Thu, 20 Oct 2022 18:10:27 -0700 Subject: [PATCH] Use the i18n library for date/time formatting --- src/common/i18n.mjs | 7 +++++++ src/common/time.js | 8 -------- src/components/ScheduleBox.vue | 5 ++--- src/components/ScheduleRow.vue | 6 +++--- src/components/SplatfestBox.vue | 5 ++--- src/components/gear/DailyDropGear.vue | 3 +-- src/components/salmonrun/ExpandedSalmonRunRow.vue | 6 +++--- src/components/salmonrun/SalmonRunRow.vue | 6 +++--- src/components/screenshots/DailyDropGear.vue | 1 - 9 files changed, 21 insertions(+), 26 deletions(-) diff --git a/src/common/i18n.mjs b/src/common/i18n.mjs index 89aab02..7dab580 100644 --- a/src/common/i18n.mjs +++ b/src/common/i18n.mjs @@ -22,6 +22,12 @@ export const locales = [ export const defaultLocale = locales.find(l => l.code === 'en-US'); +const datetimeFormats = { + dateTimeShort: { month: 'numeric', day: 'numeric', hour: 'numeric', minute: '2-digit' }, + dateTimeShortWeekday: { month: 'numeric', weekday: 'short', day: 'numeric', hour: 'numeric', minute: '2-digit' }, + time: { hour: 'numeric', minute: '2-digit' }, +}; + let i18n = null; export function initializeI18n() { @@ -30,6 +36,7 @@ export function initializeI18n() { locale: currentLocale().code, fallbackLocale: 'en-US', messages: { ...languages }, + datetimeFormats: locales.reduce((result, locale) => ({ ...result, [locale.code]: datetimeFormats }), {}), }); // Listen for local storage changes diff --git a/src/common/time.js b/src/common/time.js index 7e3b158..807cc3b 100644 --- a/src/common/time.js +++ b/src/common/time.js @@ -1,14 +1,6 @@ import { useI18n } from 'vue-i18n'; import { useTimeStore } from '../stores/time'; -export function formatDateTime(value) { - return (new Date(value)).toLocaleString(undefined, { month: 'numeric', day: 'numeric', hour: 'numeric', minute: '2-digit' }); -} - -export function formatTime(value) { - return (new Date(value)).toLocaleTimeString(undefined, { hour: 'numeric', minute: '2-digit' }); -} - function getDurationParts(value) { let negative = (value < 0) ? '-' : ''; value = Math.abs(value); diff --git a/src/components/ScheduleBox.vue b/src/components/ScheduleBox.vue index 11be975..8d8ce19 100644 --- a/src/components/ScheduleBox.vue +++ b/src/components/ScheduleBox.vue @@ -27,9 +27,9 @@
- {{ formatTime(store.activeSchedule.startTime) }} + {{ $d(store.activeSchedule.startTime, 'time') }} – - {{ formatTime(store.activeSchedule.endTime) }} + {{ $d(store.activeSchedule.endTime, 'time') }}
@@ -82,7 +82,6 @@ import ScheduleRow from './ScheduleRow.vue'; import battleRegularSvg from '@/assets/img/modes/regular.svg'; import battleBankaraSvg from '@/assets/img/modes/bankara.svg'; import RuleIcon from './RuleIcon.vue'; -import { formatTime } from '../common/time'; import SquidTape from './SquidTape.vue'; const props = defineProps({ diff --git a/src/components/ScheduleRow.vue b/src/components/ScheduleRow.vue index 55d52d4..53b35f1 100644 --- a/src/components/ScheduleRow.vue +++ b/src/components/ScheduleRow.vue @@ -32,9 +32,9 @@
- {{ formatTime(props.schedule.startTime) }} + {{ $d(props.schedule.startTime, 'time') }} – - {{ formatTime(props.schedule.endTime) }} + {{ $d(props.schedule.endTime, 'time') }}
@@ -60,7 +60,7 @@