fix: use browser locales when displaying date

This commit is contained in:
Valentin Kaelin 2020-04-03 12:40:22 +02:00
parent 0b087e7e06
commit 897196b048
3 changed files with 5 additions and 7 deletions

View file

@ -102,7 +102,7 @@ export default {
for (let i = 1; i <= nbDaysInGrid; i++) {
const day = new Date()
day.setDate(day.getDate() - nbDaysInGrid + i)
const formattedDay = day.toLocaleString('fr', this.options)
const formattedDay = day.toLocaleString(undefined, this.options)
this.gridDays.push({
date: formattedDay,
@ -119,7 +119,7 @@ export default {
for (const key in this.matches) {
const match = this.matches[key]
const matchTime = new Date(match.timestamp)
const formattedTime = matchTime.toLocaleString('fr', this.options)
const formattedTime = matchTime.toLocaleString(undefined, this.options)
const dayOfTheMatch = this.gridDays.filter(
e => e.date === formattedTime

View file

@ -19,9 +19,7 @@ export function timeDifference(previous) {
} else if (elapsed < msPerWeek) {
return Math.round(elapsed / msPerDay) + ' days ago'
} else {
const oldDate = new Date(previous)
const day = oldDate.getDate() < 10 ? '0' + oldDate.getDate() : oldDate.getDate()
const month = oldDate.getMonth() < 9 ? '0' + (oldDate.getMonth() + 1) : (oldDate.getMonth() + 1)
return day + '.' + month + '.' + oldDate.getFullYear().toString().substr(-2)
const dateOptions = { day: '2-digit', month: '2-digit', year: 'numeric' }
return new Date(previous).toLocaleString(undefined, dateOptions).replace(/\//g, '.')
}
}

View file

@ -16,7 +16,7 @@ export function createMatchData(matches) {
const date = new Date(match.date)
const dateOptions = { day: '2-digit', month: '2-digit', year: 'numeric' }
const timeOptions = { hour12: false, hour: '2-digit', minute: '2-digit' }
match.fullDate = { date: date.toLocaleString('fr', dateOptions), time: date.toLocaleString('fr', timeOptions) }
match.fullDate = { date: date.toLocaleString(undefined, dateOptions), time: date.toLocaleString(undefined, timeOptions) }
match.date = timeDifference(match.date)
match.map = maps[match.map]