Skip to content

Let ZoneDateTime parse date time strings with reduced precision to be more ISO8601 compliant. #505

@Para7etamol

Description

@Para7etamol

Hi there,

I feel this is related to #470, but has another focus.

ISO8601 generally allows to drop the least-significant components of the time specification. Consequently DateTime can parse

julia> dt=DateTime("2026-01-20T09:00",dateformat"yyyy-mm-dd\THH:MM:SS")
2026-01-20T09:00:00

where the seconds are left out although they are specified. DateTime adds zeros here.

I would love ZonedDateTime to do the same, but

julia> zdt=ZonedDateTime("2026-01-20T09:00+01:00",dateformat"yyyy-mm-dd\THH:MM:SSzzz")
ERROR: ArgumentError: Unable to parse string "2026-01-20T09:00+01:00" using format dateformat"yyyy-mm-dd\THH:MM:SSzzz". Unable to parse date time. Expected directive Delim(:) at char 17
Stacktrace: ...

For millis it's nearly the same story, because DateTime omits them in the output if zero instead of adding zeros:

julia> dt=DateTime("2026-01-20T09:00",dateformat"yyyy-mm-dd\THH:MM:SS.sss")
2026-01-20T09:00:00

So aside from better ISO 8601 compliance, maybe it could fix #470, if ZonedDateTime would allow dropping the least-significant parts.

Sincerly yours

Para7etamol

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions