-
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
implement Iterator #152
Comments
What time step to use? Days, Months, Years, Decades?
…On Sun, May 14, 2017 at 3:55 AM, Geobert Quach ***@***.***> wrote:
Hi,
I'm new at Rust so I might have missed something here.
I have two NaiveDate and I'd like to write:
for d in start..end {
}
but it needs the Iterator Trait.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#152>, or mute the thread
<https://github.com/notifications/unsubscribe-auth/AJSF1pqzd0RcLQeXQ3LdPsanepC64qt5ks5r5s-dgaJpZM4NaVGx>
.
|
oh, true, so the only choice is to do our own, maybe provide a factory to generate an iterator with needed parameters? For my needs, I've done this:
|
Daywise iterator for |
I think implementing Maybe a couple of methods could make this more explicit (
To add these methods we don't really need to implement |
So I have submitted a PR with an implementation of an Iterator over the days with a step of 1 day for It is an Once this iterator implements Iterating over day ranges is also trivial to add, you just do Finally, iterating over months... I tried to do this, and succeeded, just to realize I had failed. I don't think that iterating over months should be in the library, because there is no good solution for it. All of the following solutions are good and valid, depending on the use case:
IMO none of these is wrong, but none of these solutions work for everybody either. We should maybe add some examples to the library showing how to implement these so that users can refer to them, but we should not add APIs to the library for any of these. None of them is better than another. |
I think the smallest difference between naive dates (1 day) is very intuitive. I'm new to Rust, when trying to implement |
Hi, I think this feature request makes sense. Perhaps not as is, but being able to produce a range of dates easily is very useful. If there's no implementation already I can try my hand at this; any thoughts? |
Perhaps a similar method for NaiveDateTime would be useful? I imagine a method that takes a duration and end-time, or a number of steps, and produces an iterator. Would the maintainers be open to PRs along this line for NaiveDate and NaiveDateTime? |
I would be super happy to accept a PR implementing iterators! I don't think a raw If someone decides to implement this please make sure to test around some daylight savings time changes in both directions, it's fine if tests fail in the initial PR, we can discuss the right behavior in review. |
To be clear, I don't think that implementing |
I think @gnzlbg made PR #208 and described everything above. Again, I don't understand why some people find it strange that canonical way to iterate over a range of dates should be by one day. That's the smallest step. Unfortunately, Iterating by month or year is less intuitive because, unlike weeks, months and years are not fixed-sized and depend on the year. What happens if you iterate by month/year starting from February 29. There is no obvious choice. Methods like start/end of (next/prev) month/year, are much more useful and explicit. |
Oh, yes they did. I've been working my way through the backlog, I'll get to that one asap, if they're still interested in getting it going.
The fact that the logic is more complex is part of the reason that you'd want to push it down into a library where fixes can be shared. Iterating over days is trivial because you can just iterate over integers added to a base day. |
I didn't mean it's necessary complex, just ambiguous. For example, if you choose "always skip 30 days" for month iteration, as somebody mentioned above, then it's simple. My point was that there are different ways to "iterate by month" from an arbitrary date, so it's likely that a user will have a little bit different requirements. In general, I don't think it has to do with complex/trivial. Iterating over a |
By the way, thanks for working on chrono! I'm just trying to be helpful! |
|
I have a use case where I need to load a schedule into a cache and for fast API lookups, I need to explode a simple start/end date-time timestamp into individual entries for the length of the range at a specific granularity, defined by an environment variable. The environment variable lets us make different choices for development vs testing vs production based on memory constraints. At the moment, I'm stuck with building a custom iterator to do all of this, and on top of that, I'd really like for this iterator to be parallelized where it makes sense using rayon. |
@brianbruggeman note that the discussion was about |
I don't think my point is invalidated by considering a NaiveDate rather than a Date+Time timestamp. I gave the timestamp as an example, but Duration could just as easily be days and weeks as it could be anything else. But consider that data is often segregated by different kinds of time, it seems like a developer might want to iterate over months and years or possibly decades. In my case, I care about "near" real time, so I'm less likely to be concerned about larger times. But from my perspective, Date is really just another kind of time and is lumped into the same type of problems and constraints from a usability perspective. |
@brianbruggeman sure, but then you need to define what it means to iterate |
Hi,
I'm new at Rust so I might have missed something here.
I have two NaiveDate and I'd like to write:
but it needs the Iterator Trait.
The text was updated successfully, but these errors were encountered: