diff options
-rw-r--r-- | src/iter.rs | 25 | ||||
-rw-r--r-- | tests/rrule.rs | 34 |
2 files changed, 39 insertions, 20 deletions
diff --git a/src/iter.rs b/src/iter.rs index 2673059..561585e 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -201,7 +201,7 @@ pub fn iter(iter_result: &mut IterResult, options: &mut ParsedOptions) -> Vec<Da counter_date.hour() as usize, counter_date.minute() as usize, counter_date.second() as usize, - counter_date.timestamp_subsec_millis() as usize, + 0, ); } @@ -212,7 +212,7 @@ pub fn iter(iter_result: &mut IterResult, options: &mut ParsedOptions) -> Vec<Da pub fn increment_counter_date( counter_date: DateTime<Utc>, options: &ParsedOptions, - _filtered: bool, + filtered: bool, ) -> DateTime<Utc> { match options.freq { Frequenzy::YEARLY => counter_date @@ -249,7 +249,26 @@ pub fn increment_counter_date( counter_date + Duration::days(day_delta as i64) } Frequenzy::DAILY => counter_date + Duration::days(options.interval as i64), - Frequenzy::HOURLY => counter_date + Duration::hours(options.interval as i64), + Frequenzy::HOURLY => { + let mut new_hours = counter_date.hour() as usize; + if filtered { + new_hours += ((23 - new_hours) as f32 / options.interval as f32).floor() as usize + * options.interval; + } + + loop { + new_hours += options.interval; + if options.byhour.is_empty() + || options + .byhour + .iter() + .any(|bh| *bh == (new_hours % 24) as usize) + { + break; + } + } + counter_date.with_hour(0).unwrap() + Duration::hours(new_hours as i64) + } Frequenzy::MINUTELY => counter_date + Duration::minutes(options.interval as i64), Frequenzy::SECONDLY => counter_date + Duration::seconds(options.interval as i64), } diff --git a/tests/rrule.rs b/tests/rrule.rs index 8ecbe56..5d73eeb 100644 --- a/tests/rrule.rs +++ b/tests/rrule.rs @@ -3597,7 +3597,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3629,7 +3629,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3661,7 +3661,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3693,7 +3693,7 @@ mod test { bymonth: vec![1, 3], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3725,7 +3725,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3757,7 +3757,7 @@ mod test { bymonth: vec![1, 3], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3789,7 +3789,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![1, 3], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3823,7 +3823,7 @@ mod test { bymonth: vec![1, 3], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![1, 3], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3855,7 +3855,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![1, 3], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3887,7 +3887,7 @@ mod test { bymonth: vec![1, 3], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![1, 3], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3919,7 +3919,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3956,7 +3956,7 @@ mod test { bymonth: vec![4, 7], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![], byminute: vec![0], @@ -3989,7 +3989,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![20], byminute: vec![0], @@ -4021,7 +4021,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![0], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![1], byminute: vec![0], @@ -4053,7 +4053,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![6], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![52], byminute: vec![0], @@ -4085,7 +4085,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![6], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![-1], byminute: vec![0], @@ -4117,7 +4117,7 @@ mod test { bymonth: vec![], dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), byweekday: vec![0], - byhour: vec![9], + byhour: vec![], bysetpos: vec![], byweekno: vec![53], byminute: vec![0], |