mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-23 07:09:35 +02:00
22 lines
485 B
JavaScript
22 lines
485 B
JavaScript
'use strict'
|
|
|
|
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: timezone
|
|
}).toFormat('yyyyMMdd')
|
|
}
|
|
|
|
module.exports = formatDate
|