Skip to content

Implement DateTime diffing methods Until and Since #83

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

Merged
merged 4 commits into from
Jul 17, 2024
Merged

Conversation

nekevss
Copy link
Member

@nekevss nekevss commented Jul 16, 2024

This implements diffing for DateTime and the corresponding since and until methods.

TODO: add basic unit tests for the methods.

@nekevss nekevss added C-enhancement New feature or request C-api Changes related to the public API labels Jul 16, 2024
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Nice work! We should avoid using unsafe where it's not required.


// Step 12
match sign {
crate::Sign::Positive => Ok(result),
Copy link
Member

Choose a reason for hiding this comment

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

You can avoid the panic by also matching against Sign::Zero here.

DifferenceSettings {
largest_unit: None,
smallest_unit: Some(smallest),
increment: Some(unsafe { RoundingIncrement::new_unchecked(increment) }),
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer if we didn't use unsafe here. We can just use try_new and unwrap.

@nekevss nekevss requested a review from jedel1043 July 17, 2024 21:49
Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

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

Nice job!

@nekevss nekevss merged commit 44ed454 into main Jul 17, 2024
5 checks passed
@nekevss nekevss deleted the impl-dt-diffing branch July 19, 2024 02:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-api Changes related to the public API C-enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants