Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Fails to round-trip encode/decode dates

See original GitHub issue

Thank you for these libraries! Unfortunately both msgpackr and cbor-x currently fail on various dates.

For cbor-x, it seems like we start to lose milliseconds due to floating point errors for dates > 2038:

    // Expected: 2039-07-05T16:22:35.792Z
    // Received: 2039-07-05T16:22:35.791Z

    // Expected: 2038-08-06T00:19:02.911Z
    // Received: 2038-08-06T00:19:02.910Z

For msgpackr, it doesn’t seem to have that same floating point error, but it does “wrap around” after 2106:

   // Expected: 2106-08-05T18:48:20.323Z
   // Received: 1970-06-29T12:20:04.323Z

   // Expected: 2110-02-18T14:51:07.995Z
   // Received: 1974-01-12T08:22:51.995Z

FWIW, this comment helped me fix the issue with cbor-x by using string encoding:

By encoding as ISO 8601, cbor-x seems to handle any date I throw at it. But the default behavior feels like a bug - the libraries currently don’t properly encode the full range of JS date objects.

IMHO, the default behavior should be to correctly encode any date without any loss, with an option to optimize for message size. But I realize that would be a breaking change - it would be nice if the docs at least mentioned the current limitations of date encoding.

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

sbkingcommented, Apr 20, 2022

Thank you! It’s working great now

kriszypcommented, Apr 20, 2022

Ok, published the fix for date time rounding issue and tag 0 handling in cbor-x@v1.2.1. I also fixed the issue in msgpackr as well. Thank you for the detailed report!

Read more comments on GitHub >

github_iconTop Results From Across the Web

IDNA does not round-trip - Stack Overflow
The error "IDNA does not round-trip" means that the module gets a different result when decoding and encoding the string. By looking at...
Read more >
Problem with encoding dates in · Issue #176 · mogui ...
The CSV serializer seems to fail with the roundtrip encoding of dates (atleast with OrientDB 2.2.5). I will write a script that tests...
Read more >
URL fails to decode when it is a generic argument and ...
URL fails to decode when it is a generic argument and `GenericArgument(from: decoder)` is used. In the following code, GoodURLContainer decodes ...
Read more >
Encoding/Decoding date from record - SmartClient Forums
Uhm.. the docs tell you that to round-trip dates, you must use dateFormat:dateConstructor. You have configured xmlSchema instead.
Read more >
jsonpickle API
By default, jsonpickle tries the next backend when decoding or encoding using a backend fails. This can make it difficult to force jsonpickle...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Post

No results found

github_iconTop Related Hashnode Post

No results found