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

Fix parsing when the local tz offset spans across midnight #55

Closed

Conversation

sruggier
Copy link

This should fix #36.

Previously, the implementation lived in parse_relative_time_at_date, but
the "at_date" part is buggy when the local and UTC times have different
dates, so removing the dependency on that code from parse_relative_time
fixes a bug related to that.
This was an internal-only function, which is now not called by anything,
so it can be safely removed.
@sruggier sruggier force-pushed the fix-local-tz-offsets-across-midnight branch from 2375d7d to 2786540 Compare October 24, 2023 14:53
Copy link
Member

@tertsdiepraam tertsdiepraam left a comment

Choose a reason for hiding this comment

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

I understand what you're trying to do, but I don't think it's entirely correct in the long run. The problem is that we cannot return just a chono::Duration because the length of the duration might depend on the date. For instance, if a duration of 1 month is given, that cannot be accurately represented in a chrono::Duration, because that only stores seconds and nanoseconds.

I think the calculation in parse_relative_time_at_date can probably be improved though.

@sruggier
Copy link
Author

I haven't changed the type returned by the function, so I don't think it's possible for this change to create a regression related to longer durations. Would you mind giving me a more concrete example of an input that wouldnt be handled correctly, to help me understand what you're referring to?

@tertsdiepraam
Copy link
Member

So, you're right, you've not regressed anything, but it would've if the rest up the code was correct (and obviously that's on us 😄). Basically, what the current main branch is currently doing, for example, is assuming that a month is 30 days. That's just wrong. It reality, the number of days that a month takes depends on the reference date.

However, there is an alternative solution that we could explore. Which is where we don't return just a chrono::Duration, but a custom duration, that includes the number of months as a separate field, for example. Like this library is doing: https://docs.rs/chronoutil/latest/src/chronoutil/relative_duration.rs.html#11-14. That would work too.

Sorry, this library is in a pretty weird state at the moment, because the original implementation did not foresee issues like this. I should sit down and really fix it up at some point.

@sruggier
Copy link
Author

sruggier commented Nov 2, 2023

So, how do you want to proceed? I think it would be reasonable to merge this as-is, and open an issue to track the other problem. One can always revert the test removals later on if they'd be useful after making the later change.

If you'd prefer to fix both problems at the same.time, though, then it would be good to confirm that.

@tertsdiepraam
Copy link
Member

No, sorry, I really can't merge this as is, because I've been really trying to push this library in the right direction (always having a reference datetime) and then this does not make sense. It's all related to the issues summarized here: #56. Maybe, a solution would be to make this library not accept a NaiveDate as reference but a full Datetime and then add the parsed duration to that? I'll bump this library on my todo list and give it a good look today :)

@sruggier
Copy link
Author

sruggier commented Nov 2, 2023

Yes, NaiveDates are part of the problem here.

@sylvestre
Copy link
Contributor

should we close this PR ? thanks

@tertsdiepraam
Copy link
Member

Thanks for your work on this! Feel free to reopen this or open a new PR if you think that we can give this a second shot.

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.

Cargo test fails at 0:20 JST
3 participants