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

⏰ Add td_*seconds serde Serialize and Deserialize functions for TimeDelta #1652

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

tosti007
Copy link

Fixes #117

This PR copy-pastes the current implementation for DateTime such that we have equal implementations for DeltaTime.

I opted to add the logic to the existing serde.rs file. However, I think this might be the wrong place and a better solution would be to move the main.rs's serde module combined with this serde.rs file to a separate src/serde.rs file, thoughts?

PS:
I am just doing a drive-by PR on this crate, so I don't really know what the exact requirements are regarding testing ect. Please let me know!

@tosti007 tosti007 changed the title Add td_*seconds serde Serialize and Deserialize functions for TimeDelta ⏰ Add td_*seconds serde Serialize and Deserialize functions for TimeDelta Jan 16, 2025
Copy link
Member

@djc djc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to see at least one basic round-tripping test for each of these.

src/datetime/serde.rs Outdated Show resolved Hide resolved
S: ser::Serializer,
{
serializer.serialize_i64(td.num_nanoseconds().ok_or(ser::Error::custom(
"value out of range for a timedelta with nanosecond precision",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's capitalize TimeDelta in these error messages, too.

Copy link
Author

@tosti007 tosti007 Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the timestamp versions of these functions the "timestamp" is also lower cased, hence I did so here too. So I think there are three options:

  1. Leave them lowercased.
  2. Uppercase just timedelta
  3. Uppercase both

What do you prefer?

Copy link
Member

@djc djc Jan 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Timestamp is an English word commonly spelled as one word. Time delta is not an actual word and is more of a term of art introduced by this library's API. So I think it makes sense to capitalize TimeDelta in these errors even if the same is not true for timestamp.

src/lib.rs Outdated Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
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.

Add Serialize/Deserialize for Duration
2 participants