Switch to infinite scroll (Full book)

Parsing Calendar components

A timezone is required to disambiguate the calendar components.

derive JS Dates from timezone aware objects

From a Luxon object:

const dt = DateTime.fromObject(
    {
        year: 2015,
        month: 6,
        day: 18,
        hour: 13,
        minute: 13,
    },
    {
        zone: "Europe/Paris",
    },
)

const birthDate = dt.toJSDate()

From a Temporal ZonedDateTime object (through milliseconds conversion):

const dt = Temporal.ZonedDateTime.from({
    year: 2015,
    month: 6,
    day: 18,
    hour: 13,
    minute: 13,
    timeZone: "Europe/Paris",
})

const birthDate = new Date(dt.toInstant().epochMilliseconds)

derive the JS date from an ISO string

With an UTC offset in the date time string. This is worse than providing a timezone because it requires knowledge about the offset of the location at this date.

new Date(isoString)

new Date("2015-06-18T13:13+02:00") // offset ISO, minutes granularity
new Date("2015-06-18T13:13:00+02:00") // offset ISO, seconds granularity
new Date("2015-06-18T11:13:00.000Z") // UTC ISO (Z)

helpers that assume UTC

from a date-only ISO string:

new Date("2015-06-18") // assumed to be UTC

helpers that assume host timezone (brittle, do not use)

The helpers assume the local timezone:

const birth = new Date(2015, 5 /* June */, 18, 13, 13)
new Date("2015-06-18T13:13:00")
earlymorning logo

Parsing Calendar components

A timezone is required to disambiguate the calendar components.

derive JS Dates from timezone aware objects

From a Luxon object:

const dt = DateTime.fromObject(
    {
        year: 2015,
        month: 6,
        day: 18,
        hour: 13,
        minute: 13,
    },
    {
        zone: "Europe/Paris",
    },
)

const birthDate = dt.toJSDate()

From a Temporal ZonedDateTime object (through milliseconds conversion):

const dt = Temporal.ZonedDateTime.from({
    year: 2015,
    month: 6,
    day: 18,
    hour: 13,
    minute: 13,
    timeZone: "Europe/Paris",
})

const birthDate = new Date(dt.toInstant().epochMilliseconds)

derive the JS date from an ISO string

With an UTC offset in the date time string. This is worse than providing a timezone because it requires knowledge about the offset of the location at this date.

new Date(isoString)

new Date("2015-06-18T13:13+02:00") // offset ISO, minutes granularity
new Date("2015-06-18T13:13:00+02:00") // offset ISO, seconds granularity
new Date("2015-06-18T11:13:00.000Z") // UTC ISO (Z)

helpers that assume UTC

from a date-only ISO string:

new Date("2015-06-18") // assumed to be UTC

helpers that assume host timezone (brittle, do not use)

The helpers assume the local timezone:

const birth = new Date(2015, 5 /* June */, 18, 13, 13)
new Date("2015-06-18T13:13:00")