2017-11-12 00:45:51 +01:00
|
|
|
'use strict'
|
|
|
|
|
2018-09-24 15:40:00 +02:00
|
|
|
const {DateTime, IANAZone} = require('luxon')
|
2017-11-12 00:45:51 +01:00
|
|
|
|
2018-09-24 15:40:00 +02:00
|
|
|
const timezones = new WeakMap()
|
|
|
|
|
|
|
|
// 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
|
|
|
}
|
|
|
|
|
2017-11-12 00:53:34 +01:00
|
|
|
module.exports = formatDate
|