-
Notifications
You must be signed in to change notification settings - Fork 547
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
Conversation
/// assert_eq!(count, 4); | ||
/// ``` | ||
#[inline] | ||
pub fn iter_days(&self) -> NaiveDateDaysIterator { |
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.
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 ).
@kennytm ? |
@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. |
@gnzlbg Why am I involved? 😅 |
@quodlibetor I personally like C++'s approach to date and time quite a bit. It has three libraries:
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:
Some literature:
|
This was merged in #457 |
This PR implements an
iter_days()
method forNaiveDate
that returns an iterator from the current date untilMAX_DATE
with a step-size of1
day. It closes #152 .The
Iterator
is anExactSizeIterator
because the distance in days from any date untilMAX_DATE
can be computed inO(1)
.Since
Step
,TrustedLen
, andFusedIterator
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 of7
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).