Skip to content
Discussion options

You must be logged in to vote

It's because end_date - current_date produces a Span representing the number of days between the dates, and Date::series accepts an increment amount. So if the difference between two days is 14 days, then series will return dates spaced 14 days apart. What you want instead is to count by single days and take elements while they are less than the end_date. Putting it all together, you get this:

use jiff::{
    civil::{Date, Weekday},
    ToSpan, Zoned,
};

fn main() -> anyhow::Result<()> {
    let current_date = Zoned::now().date();
    let end_date: Date = current_date + 2.weeks();

    let days_left = current_date
        .series(1.day())
        .take_while(|d| d <= &end_date)
        .f…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@isosphere
Comment options

Answer selected by isosphere
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants