speed up date+time formatting

This commit is contained in:
Jannis R 2018-09-24 15:40:00 +02:00
parent ed3ecd7b4d
commit 2a6b0dc507
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
3 changed files with 25 additions and 4 deletions

View file

@ -1,11 +1,21 @@
'use strict'
const {DateTime} = require('luxon')
const {DateTime, IANAZone} = require('luxon')
const timezones = new WeakMap()
// todo: change to `(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, {
locale: profile.locale,
zone: profile.timezone
zone: timezone
}).toFormat('yyyyMMdd')
}

View file

@ -1,11 +1,21 @@
'use strict'
const {DateTime} = require('luxon')
const {DateTime, IANAZone} = require('luxon')
const timezones = new WeakMap()
// todo: change to `(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, {
locale: profile.locale,
zone: profile.timezone
zone: timezone
}).toFormat('HHmmss')
}

View file

@ -4,6 +4,7 @@ const {DateTime, IANAZone} = require('luxon')
const timezones = new WeakMap()
// todo: change to `(profile) => (date, time) => {}`
const parseDateTime = (profile, date, time) => {
const pDate = [date.substr(-8, 4), date.substr(-4, 2), date.substr(-2, 2)]
if (!pDate[0] || !pDate[1] || !pDate[2]) {