Skip to content

provide a more convenient way to (de)serialize an integer number of units since the Unix epoch #101

@BurntSushi

Description

@BurntSushi

See #100 for a use case and how to do it with Jiff at time of writing. That is, this issue isn't about adding anything you can't already do with Jiff today, but as the answer I posted in #100 shows, coming up with your own solution to this is a little annoying.

Chrono provides a serde sub-module that handles use cases like this. For example: https://docs.rs/chrono/latest/chrono/serde/ts_seconds_option/index.html

I do like the simplicity of Chrono's approach here. In particular, it avoids defining a new wrapper type for each option, which would be a lot more involved. Instead, you just use it like serde(with = "chrono::serde::ts_seconds_option"). I'm not a huge fan of the naming, but it isn't bad.

So probably we copy Chrono's approach here? I'm struggling to see something better.

It'd be nice to make it "automatic," but we can't really, because I think timestamps in seconds and milliseconds are pretty common and it's impossible to disambiguate between them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions