mirror of
https://github.com/public-transport/db-vendo-client.git
synced 2025-02-22 22:59:35 +02:00
24 lines
542 B
JavaScript
24 lines
542 B
JavaScript
import {DateTime, IANAZone} from 'luxon';
|
|
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js';
|
|
|
|
// 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(Number(when), {
|
|
locale: profile.locale,
|
|
zone: timezone,
|
|
})
|
|
.toFormat('yyyy-MM-dd');
|
|
};
|
|
|
|
export {
|
|
formatDate,
|
|
};
|