Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support to serialize and deserialize timestamps with different resolutions #648

Merged
merged 3 commits into from
Jan 31, 2024

Conversation

ogarcia
Copy link
Contributor

@ogarcia ogarcia commented Jan 28, 2024

As discussed in #647 this merge request adds the ability to serialize and deserialize timestamps with milliseconds, microseconds and nanoseconds.

For now I have only implemented the milliseconds because I want to see if it looks right to you @jhpratt if so then I do the rest.

The idea is that you can do the following:

use serde::{Deserialize, Serialize};
use time::serde::timestamp;
use time::OffsetDateTime;

#[derive(Serialize, Deserialize, Debug)]
struct TimestampSeconds {
    #[serde(with = "timestamp")]
    dt: OffsetDateTime,
}

#[derive(Serialize, Deserialize, Debug)]
struct TimestampMilliseconds {
    #[serde(with = "timestamp::milliseconds")]
    dt: OffsetDateTime,
}

@jhpratt
Copy link
Member

jhpratt commented Jan 29, 2024

At quick glance this looks correct. My nits are minor at this point: I would split the tests for seconds/milliseconds/etc. into different functions, rather than just keeping it as one. I'd also indicate in the module documentation that it's the Unix timestamp in milliseconds (as appropriate).

@ogarcia
Copy link
Contributor Author

ogarcia commented Jan 29, 2024

Done. I have added your suggestions. In the documentation of each module I have detailed if it is milliseconds/etc. and I have separated the tests into different functions. 😄

@ogarcia ogarcia marked this pull request as ready for review January 29, 2024 08:04
@jhpratt jhpratt linked an issue Jan 31, 2024 that may be closed by this pull request
@jhpratt
Copy link
Member

jhpratt commented Jan 31, 2024

LGTM. Thanks and good work!

@jhpratt jhpratt merged commit be932d8 into time-rs:main Jan 31, 2024
18 of 19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Cannot Deserialize timestamp with milliseconds
2 participants