mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
speed up date+time formatting ⚡
This commit is contained in:
parent
ed3ecd7b4d
commit
2a6b0dc507
3 changed files with 25 additions and 4 deletions
|
@ -1,11 +1,21 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const {DateTime} = require('luxon')
|
const {DateTime, IANAZone} = require('luxon')
|
||||||
|
|
||||||
|
const timezones = new WeakMap()
|
||||||
|
|
||||||
|
// todo: change to `(profile) => (when) => {}`
|
||||||
const formatDate = (profile, when) => {
|
const formatDate = (profile, when) => {
|
||||||
|
let timezone
|
||||||
|
if (timezones.has(profile)) timezone = timezones.get(profile)
|
||||||
|
else {
|
||||||
|
timezone = new IANAZone(profile.timezone)
|
||||||
|
timezones.set(profile, timezone)
|
||||||
|
}
|
||||||
|
|
||||||
return DateTime.fromMillis(+when, {
|
return DateTime.fromMillis(+when, {
|
||||||
locale: profile.locale,
|
locale: profile.locale,
|
||||||
zone: profile.timezone
|
zone: timezone
|
||||||
}).toFormat('yyyyMMdd')
|
}).toFormat('yyyyMMdd')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,21 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const {DateTime} = require('luxon')
|
const {DateTime, IANAZone} = require('luxon')
|
||||||
|
|
||||||
|
const timezones = new WeakMap()
|
||||||
|
|
||||||
|
// todo: change to `(profile) => (when) => {}`
|
||||||
const formatTime = (profile, when) => {
|
const formatTime = (profile, when) => {
|
||||||
|
let timezone
|
||||||
|
if (timezones.has(profile)) timezone = timezones.get(profile)
|
||||||
|
else {
|
||||||
|
timezone = new IANAZone(profile.timezone)
|
||||||
|
timezones.set(profile, timezone)
|
||||||
|
}
|
||||||
|
|
||||||
return DateTime.fromMillis(+when, {
|
return DateTime.fromMillis(+when, {
|
||||||
locale: profile.locale,
|
locale: profile.locale,
|
||||||
zone: profile.timezone
|
zone: timezone
|
||||||
}).toFormat('HHmmss')
|
}).toFormat('HHmmss')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ const {DateTime, IANAZone} = require('luxon')
|
||||||
|
|
||||||
const timezones = new WeakMap()
|
const timezones = new WeakMap()
|
||||||
|
|
||||||
|
// todo: change to `(profile) => (date, time) => {}`
|
||||||
const parseDateTime = (profile, date, time) => {
|
const parseDateTime = (profile, date, time) => {
|
||||||
const pDate = [date.substr(-8, 4), date.substr(-4, 2), date.substr(-2, 2)]
|
const pDate = [date.substr(-8, 4), date.substr(-4, 2), date.substr(-2, 2)]
|
||||||
if (!pDate[0] || !pDate[1] || !pDate[2]) {
|
if (!pDate[0] || !pDate[1] || !pDate[2]) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue