2022-05-07 16:17:37 +02:00
|
|
|
import {DateTime, IANAZone} from 'luxon'
|
2022-11-30 17:43:40 +01:00
|
|
|
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
|
2018-09-24 15:40:00 +02:00
|
|
|
|
|
|
|
// todo: change to `(profile) => (when) => {}`
|
2017-11-12 14:52:04 +01:00
|
|
|
const formatDate = (profile, when) => {
|
2018-09-24 15:40:00 +02:00
|
|
|
let timezone
|
|
|
|
if (timezones.has(profile)) timezone = timezones.get(profile)
|
|
|
|
else {
|
|
|
|
timezone = new IANAZone(profile.timezone)
|
|
|
|
timezones.set(profile, timezone)
|
|
|
|
}
|
|
|
|
|
2017-12-11 17:21:50 +01:00
|
|
|
return DateTime.fromMillis(+when, {
|
|
|
|
locale: profile.locale,
|
2018-09-24 15:40:00 +02:00
|
|
|
zone: timezone
|
2017-12-11 17:21:50 +01:00
|
|
|
}).toFormat('yyyyMMdd')
|
2017-11-12 00:45:51 +01:00
|
|
|
}
|
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
formatDate,
|
|
|
|
}
|