parseDateTime, format{Date,Time}: share Luxon IANAZones

This commit is contained in:
Jannis R 2022-11-30 17:43:40 +01:00
parent fc1afe0625
commit 547dd4b2a9
No known key found for this signature in database
GPG key ID: 0FE83946296A88A5
4 changed files with 9 additions and 6 deletions

View file

@ -1,6 +1,5 @@
import {DateTime, IANAZone} from 'luxon' import {DateTime, IANAZone} from 'luxon'
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
const timezones = new WeakMap()
// todo: change to `(profile) => (when) => {}` // todo: change to `(profile) => (when) => {}`
const formatDate = (profile, when) => { const formatDate = (profile, when) => {

View file

@ -1,6 +1,5 @@
import {DateTime, IANAZone} from 'luxon' import {DateTime, IANAZone} from 'luxon'
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
const timezones = new WeakMap()
// todo: change to `(profile) => (when) => {}` // todo: change to `(profile) => (when) => {}`
const formatTime = (profile, when) => { const formatTime = (profile, when) => {

6
lib/luxon-timezones.js Normal file
View file

@ -0,0 +1,6 @@
// hafas-client profile -> luxon.IANAZone
const luxonIANAZonesByProfile = new WeakMap()
export {
luxonIANAZonesByProfile,
}

View file

@ -1,6 +1,5 @@
import {DateTime, FixedOffsetZone, IANAZone} from 'luxon' import {DateTime, FixedOffsetZone, IANAZone} from 'luxon'
import {luxonIANAZonesByProfile as timezones} from '../lib/luxon-timezones.js'
const timezones = new WeakMap()
const parseDateTime = ({profile}, date, time, tzOffset = null, timestamp = false) => { const parseDateTime = ({profile}, date, time, tzOffset = null, timestamp = false) => {
const pDate = [date.substr(-8, 4), date.substr(-4, 2), date.substr(-2, 2)] const pDate = [date.substr(-8, 4), date.substr(-4, 2), date.substr(-2, 2)]