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 a days iterator for NaiveDate #209

Closed
wants to merge 1 commit into from

Conversation

gnzlbg
Copy link
Contributor

@gnzlbg gnzlbg commented Jan 16, 2018

This PR implements an iter_days() method for NaiveDate that returns an iterator from the current date until MAX_DATE with a step-size of 1 day. It closes #152 .

The Iterator is an ExactSizeIterator because the distance in days from any date until MAX_DATE can be computed in O(1).

Since Step, TrustedLen, and FusedIterator are unstable, I have filled issue #208 to track implementing these as they become stable. The iterator can support them.

To iterate over shorter date ranges users can use .take, .take_while, ... on this iterator.

Once we implement Step for it, users will be able to iterate over weeks by using a step-size of 7 days.

Iterating over months is hard, and this PR explicitly does not address this issue. I've argued in #152 why I think that we shouldn't implement any iterator over months in the library. But if someone wants to discuss that, I've implemented some and could contribute to that discussion (but please open an issue just for that and ping me).

@gnzlbg gnzlbg mentioned this pull request Jan 16, 2018
/// assert_eq!(count, 4);
/// ```
#[inline]
pub fn iter_days(&self) -> NaiveDateDaysIterator {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I called the method iter_days but I don't know whether this is a good name. I don't actually like it and would prefer something like just .days() or .days_until_max_date() or similar (.until_end_of_days()? :D ).

@gnzlbg gnzlbg changed the title Add a days iterator for NaiveDay Add a days iterator for NaiveDate Jan 16, 2018
@gnzlbg
Copy link
Contributor Author

gnzlbg commented Feb 7, 2018

@quodlibetor ?

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Feb 7, 2018

@kennytm ?

@quodlibetor
Copy link
Contributor

@gnzlbg Thanks for this! The iterator is definitely desired, I haven't responded to this because I've been trying to clear up what the chrono API should look like, which has pushed me away from giving this a thorough review.

I do really want this, though, sorry for the delay.

@kennytm
Copy link
Contributor

kennytm commented Feb 7, 2018

@gnzlbg Why am I involved? 😅

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Feb 23, 2018

@quodlibetor I personally like C++'s approach to date and time quite a bit. It has three libraries:

  • chrono: clocks, time points, durations, and time units (using compile-time rational numbers)
  • date: very fast time-zone unaware date algorithms
  • tz: time-zone support

and each library builds on top of the previous one (date builds on chrono, tz builds on date). There were some design mistakes that could be fixed in Rust:

  • making minutes use a 64-bit integer instead of a 32-bit integer
  • exposing only a system clock and a monotonic clock (no high-resolution clock)

Some literature:

@quodlibetor
Copy link
Contributor

This was merged in #457

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.

implement Iterator
3 participants