parseISODateString

Function

Parses an ISO8601 date string into a date and a precision. This is because a) if somone entered 2018, we want to respect that and not treat it as the same as 2018-01-01 and b) you cannot naively call new Date with an ISO 8601 string that does not include time information For example, when I, here in mountain time, do new Date('2018').getFullYear() I get "2017". This is because when you do not provide time or timezone info, UTC is assumed, so new Date('2018') is 2018-01-01T00:00:00 in UTC which is actually 7 hours earlier here in mountain time.

  • parseISODateString(isoString: string) : {
    date:
    Date
    precision:
    DatePrecision
    }

Parameters

Parameter Type Default Notes
isoString Required string

Returns

{
date:
Date
precision:
DatePrecision
}

Function defined in common/src/content/_internal.ts:203