daysbetweendates/
daysbetweendates.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
//! Defines a loop for the day counter between 2 Date struct.
use crate::date::{next, Date};
///Takes a 2 date argumant first one is starter date second one is ending date. If
pub fn day_count(mut first_date: Date, last_date: Date) -> i64 {
    let mut counter: i64 = 0;
    if (last_date.year < first_date.year) 
        ||  (last_date.year == first_date.year 
            && last_date.month < first_date.month) 
        ||  (last_date.year == first_date.year
            && last_date.month == first_date.month
            && last_date.day < first_date.day){
                return -1;
            }
    loop {
        if first_date.year == last_date.year
            && first_date.month == last_date.month
            && first_date.day == last_date.day
        {
            break;
        } else {
            (first_date, counter) = next(first_date, counter);
        }
    }
    counter
}