-
Notifications
You must be signed in to change notification settings - Fork 533
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
Impl serde::Serialize and serde::Deserialize for TimeDelta #1599
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1599 +/- ##
=======================================
Coverage 91.11% 91.12%
=======================================
Files 37 37
Lines 17104 17123 +19
=======================================
+ Hits 15584 15603 +19
Misses 1520 1520 ☔ View full report in Codecov by Sentry. |
315649e
to
dfe5349
Compare
Related to #117 |
Why has it not been reviewed yet? It is very important and a must-have in 2024. |
Because chrono is a gift and you don't get to complain about gifts. Happy to have a conversation about my commercial rates for your must-haves. |
src/time_delta.rs
Outdated
@@ -62,6 +62,28 @@ pub struct TimeDelta { | |||
nanos: i32, // Always 0 <= nanos < NANOS_PER_SEC | |||
} | |||
|
|||
#[cfg(feature = "serde")] | |||
impl serde::Serialize for TimeDelta { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: I'd prefer to have the serde
import at the top of the file (with a cfg
guard if need be), to keep this code a little clear/easier to read.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's noisy here? serde::Serialize
? Would you prefer just impl Serialize
here? Also, if we import the namespace of serde
at the top, we will have one additional #[cfg(feature = "serde")]
, and this one won't go.
I think, though, the implementations might be under a mod
which has just one #[cfg(feature = "serde")]
and all the imports there and all the tests. Would it work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the serde::
prefixes throughout these impl
s. I'm less worried about the cfg
guards, but agreed that an inline mod
might be nicer here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the clarification.
I will try to do it later today if the original author won't be able to do it by that time. But this will be a separate PR, as I can't push to the author's branch.
No need to be offensive, pal. Many of us contribute to open-source projects. I can give you my rates in exchange. Should we speak this language? The meaning of the "must-have" was to emphasize that it has been more than a month for such a simple PR to be reviewed, and I believe it hasn't ever worked for anyone since the breaking change. I wasn't asking you to work overtime or to do something extra, right? Just give it a minute the next time you are going to go through the PRs. Perhaps I will contribute to this Thanks for the gift :-) |
The tone of "been reviewed yet", "very important", and "must-have" feel like you're putting on the pressure, and I'm not really a fan of your "pal" there, either. I'm open to reminders that something needs my attention, but as a volunteer maintainer I think it's reasonable you adopt a tone that's more mindful of the volunteer nature of a lot of open source maintenance. |
I am really sorry to hear you felt the pressure from my side. Note that perceiving the tone is subjective still, and again, I didn't mean anything bad to offend you or anyone else. I just stated the facts, that's all. The fact that this thing is important, in my opinion, hasn't been reviewed for a while. I was curious to know why cuz perhaps someone might have reviewed it and forgotten to close for some reason, or something has already been done, somewhere out of this GitHub repo and PR discussions, which I wasn't a part of and couldn't know otherwise. We are all volunteers, and I think even the guy who created this PR was a volunteer, an unpaid guy spending his time on this instead of spending it with his friends and family, playing games or on some other kind of entertainment or "the time for yourself". We all do that. This is GitHub, after all. I am now afraid of saying anything else about this topic, as I am afraid to be perceived as offensive. I just hope you don't feel any pressure anymore and that I meant anything bad, even if the words you saw you perceived otherwise. I don't go from a PR to a PR in random projects to say how bad someone is. Thanks for taking a look at the PR. |
Appreciate the apology. Agreed that perceiving the tone is subjective, and yet we all should try to be mindful of how our tone was perceived. FWIW, my go to ping is something like "Gentle reminder" or "Gentle ping", which I think has enough of an effect in most cases.
I think it was still in my notification queue, but snowed under by other review requests that I deemed more important.
No need to be afraid, thanks for the candor. If @Awpteamoose doesn't come back to address the comments in a few days, maybe you want to take these changes and resubmit the PR? I'd be happy to rereview and publish a release once it's merged. |
Thanks, I will borrow your ping messages :-) Yes, I will gladly make a PR. I would love to use the OOTB parser, as for now, I specify the server_allowed_unused_time = { secs = 600, nanos = 0 } This may help someone else work around this issue, so I am sharing it here. |
Has using the ISO 8601 duration format been considered? |
It would have been awesome to have it specified as ISO 8601. Actually, this was precisely the first thing I tried to no avail. @djc do you have any objections? |
I'm around, I'm AFK today but I'll address the comments tomorrow.
If there's consensus on what to do about relative units (months, years, even days) when parsing - I can use that. My opinion would be to introduce |
You could return an error for unsupported units. |
We have #1290. It feels to me like using ISO 8601 duration syntax for the value of |
The benefit of using ISO 8601 is that you improve interoperability with other systems. TimeDelta cannot support all ISO 8601 durations, but ISO 8601 can support all TimeDelta values. By using ISO 8601, other systems should be able to more easily deserialize it. |
Any implementation of |
Note that I'm not plugged into the Java world enough to know whether this has created a footgun that spurs support issues. Python's |
b784082
to
8dd3795
Compare
@pitdicker would you have a chance to have a look at this? |
8dd3795
to
3ac01e3
Compare
@pitdicker friendly ping to have a look, please. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This serialization makes sense to me. I also prefer to keep a full ISO 8601 format for a more complete type and not use it for TimeDelta
's.
Thanks! |
return Err(Error::custom("TimeDelta out of bounds")); | ||
} | ||
Ok(TimeDelta { secs, nanos }) | ||
TimeDelta::new(secs, nanos as u32).ok_or(Error::custom("TimeDelta out of bounds")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, comment after the merge. What happens if nanos
is negative?
Edit: never mind, it works out.
Could rewrite this to use ISO 8601 representation, which since 2019 allows negative durations, if preferred. However, parsing then is a little ambiguous wrt what to do about years/months.