kaj
January 11, 2021, 5:59pm
1
I have a start and an end date and want to iterate over days in between, is that possible using chrono
?
let from = Utc.ymd(2020, 12, 30);
let to = Utc.ymd(2021, 1, 2);
for date in from..=to { // Does not work
println!("{}", date);
}
This gives a compilation about Step
not beeing implemented for Date<Utc>
. Is there a way I can provide a step for the range so I can iterate over it?
[Rust Playground ] for complete example and exact error message.
Unfortunately Step
is a nightly only trait. You're probably better off adding 1 day to the date at each iteration
kaj
January 11, 2021, 6:26pm
3
Ok, I'll loop manually then. Thanks!
Chrono’s NaiveDate
has an iter_days
iterator that might be useful here. Or maybe a corresponding method could be added to chrono::Date in a future version.
2 Likes
system
Closed
April 11, 2021, 7:01pm
5
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.