spencermountain / spacetime

A lightweight javascript timezone library
http://spacetime.how/
Other
3.98k stars 184 forks source link

Leading zero in miliseconds field is ignored when parsing a string #310

Closed wokalski closed 2 years ago

wokalski commented 2 years ago
λ node
Welcome to Node.js v15.14.0.
Type ".help" for more information.
> const spacetime = require("spacetime");
> spacetime('2021-11-02T19:55:30.087772+01').format("iso");
'2021-11-02T19:55:30.877+01:00'
wokalski commented 2 years ago

https://github.com/spencermountain/spacetime/blob/4465e077beefb102475fac2f07d02b0646f9cae6/src/methods/set/set.js#L9-L15

This is the culprit.

wokalski commented 2 years ago
> parseInt("01231", 10)
1231
spencermountain commented 2 years ago

Oh my gosh, great find. Apologies for the sloppy parsing. Wanna make a pr? Thank you.

wokalski commented 2 years ago

I don't have time and insight to make a PR at this point. The parsing code is a bit convoluted and I already forgot where it was from the time I reported this issue.

spencermountain commented 2 years ago

haha, no prob. I'll do a fix this week cheers

wokalski commented 2 years ago

While youre on it I found another issue. Sorry for the syntactic differences (I'm using rescript), but you'll get the gist:

    t->equal(iso8601TimestampWithTimezone("1994-11-05T08:15:30.23-05:00"), ParsedJson(Spacetime.fromString("1994-11-05T08:15:30.23-05:00")->Spacetime.Tz.gotoCurrent), "valid date in us")

gives me (in tests):

   -    "epoch": 784041330230,
   +    "epoch": 784041330023,

The correct value comes from Date.parse.

spencermountain commented 2 years ago

hey @wokalski these appear fixed now on dev branch - will do a release in the new year

spacetime('2021-11-02T19:55:30.087772+01').format("iso")
// 2021-11-02T19:55:30.087+01:00

spacetime('1994-11-05T08:15:30.23-05:00').format("iso")
// 1994-11-05T08:15:30.230-05:00

will leave this open until then cheers

wokalski commented 2 years ago

Great

spencermountain commented 2 years ago

released as 7.0.0