2024-12-07 16:16:31 +00:00
|
|
|
import {DateTime, IANAZone} from 'luxon';
|
2024-02-06 22:58:49 +01:00
|
|
|
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js';
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
const parseDateTime = (ctx, date, time, timestamp = false) => {
|
2024-02-06 22:58:49 +01:00
|
|
|
const {profile} = ctx;
|
2023-12-05 15:01:35 +01:00
|
|
|
|
2024-02-06 22:58:49 +01:00
|
|
|
let timezone;
|
2024-12-07 16:16:31 +00:00
|
|
|
if (timezones.has(profile)) {
|
2024-02-06 22:58:49 +01:00
|
|
|
timezone = timezones.get(profile);
|
2019-03-19 11:51:35 +01:00
|
|
|
} else {
|
2024-02-06 22:58:49 +01:00
|
|
|
timezone = new IANAZone(profile.timezone);
|
|
|
|
timezones.set(profile, timezone);
|
2018-09-22 19:22:27 +02:00
|
|
|
}
|
|
|
|
|
2024-12-07 16:16:31 +00:00
|
|
|
let dt = DateTime.fromISO(time, {
|
2019-03-19 11:51:35 +01:00
|
|
|
locale: profile.locale,
|
2024-02-06 22:58:49 +01:00
|
|
|
zone: timezone,
|
|
|
|
});
|
|
|
|
return timestamp
|
|
|
|
? dt.toMillis()
|
|
|
|
: dt.toISO({suppressMilliseconds: true});
|
|
|
|
};
|
2017-11-11 22:35:41 +01:00
|
|
|
|
2022-05-07 16:17:37 +02:00
|
|
|
export {
|
|
|
|
parseDateTime,
|
2024-02-06 22:58:49 +01:00
|
|
|
};
|