Thanks to visit codestin.com
Credit goes to github.com

Skip to content

toml.parse() chokes on timestamps with both fractional times and Z #20

Description

@othiym23

I'm writing a streaming TOML generator, and am using toml to validate that the TOML I'm generating is valid. I was hacking on dates tonight and came across this oddity:

> toml.parse('ts1 = 1979-05-27T07:32:00Z')
{ ts1: Sun May 27 1979 00:32:00 GMT-0700 (PDT) }
> toml.parse('ts2 = 1979-05-27T00:32:00.999999-07:00')
{ ts2: Sun May 27 1979 00:32:00 GMT-0700 (PDT) }
> toml.parse('ts3 = 1979-05-27T07:32:00.12Z')
SyntaxError: Expected "+", "-", "_" or [0-9] but "Z" found.
> toml.parse('ts4 = ' + new Date(2017, 7, 10, 8, 34, 12, 666).toISOString())
SyntaxError: Expected "+", "-", "_" or [0-9] but "Z" found.

The workaround for now is to not use Z with fractional times, but that precludes the use of date.toISOString(), which would allow me to avoid depending on moment. It's not a huge deal either way, it's just a surprising limitation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions