summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredrik Meringdal <fredrikmeringdal@Fredriks-MacBook-Pro.local>2021-02-15 16:24:44 +0100
committerFredrik Meringdal <fredrikmeringdal@Fredriks-MacBook-Pro.local>2021-02-15 16:24:44 +0100
commit895a3ba695ce168ad73c9dac4724a98ee3c1bc76 (patch)
treeda05bea4a7742a8936624501badd628137cc29e2
parent8cc0d3ac0f8e7030ff40958ffe63f76087c0c00e (diff)
downloadrust_rrule-895a3ba695ce168ad73c9dac4724a98ee3c1bc76.zip
bug fix DST
-rw-r--r--src/rrule_iter.rs25
-rw-r--r--src/rrulestr.rs11
2 files changed, 22 insertions, 14 deletions
diff --git a/src/rrule_iter.rs b/src/rrule_iter.rs
index 64bcb5d..9a4fa8f 100644
--- a/src/rrule_iter.rs
+++ b/src/rrule_iter.rs
@@ -3,7 +3,7 @@ use crate::iter::{
};
use crate::{datetime::from_ordinal, RRule};
use crate::{datetime::Time, Frequenzy};
-use chrono::prelude::*;
+use chrono::{prelude::*, Duration};
use chrono_tz::Tz;
use std::collections::VecDeque;
@@ -22,6 +22,10 @@ impl RRuleIter {
pub fn generate(&mut self) -> bool {
let options = self.ii.options.clone();
+ if options.interval == 0 {
+ return true;
+ }
+
match options.count {
Some(count) if count == 0 => return true,
_ => (),
@@ -60,7 +64,6 @@ impl RRuleIter {
for j in 0..poslist.len() {
let res = poslist[j];
if options.until.is_some() && res > options.until.unwrap() {
- // return iter_result.get_value();
continue; // or break ?
}
@@ -88,15 +91,13 @@ impl RRuleIter {
let current_day = current_day.unwrap();
let date =
from_ordinal(self.ii.yearordinal().unwrap() + current_day, &options.tzid);
+ let date = options.tzid.ymd(date.year(), date.month(), date.day());
for k in 0..self.timeset.len() {
- let res = options
- .tzid
- .ymd(date.year(), date.month(), date.day())
- .and_hms(
- self.timeset[k].hour as u32,
- self.timeset[k].minute as u32,
- self.timeset[k].second as u32,
- );
+ let res = date.and_hms(0, 0, 0)
+ + Duration::hours(self.timeset[k].hour as i64)
+ + Duration::minutes(self.timeset[k].minute as i64)
+ + Duration::seconds(self.timeset[k].second as i64);
+
if options.until.is_some() && res > options.until.unwrap() {
return true;
}
@@ -117,10 +118,6 @@ impl RRuleIter {
}
}
- if options.interval == 0 {
- return true;
- }
-
// Handle frequency and interval
self.counter_date = increment_counter_date(self.counter_date, &options, filtered);
diff --git a/src/rrulestr.rs b/src/rrulestr.rs
index bf616ba..ee465cd 100644
--- a/src/rrulestr.rs
+++ b/src/rrulestr.rs
@@ -762,4 +762,15 @@ mod test {
.collect();
assert_eq!(instances.len(), 0);
}
+
+ #[test]
+ fn daytime_savings() {
+ let rrule: RRule =
+ "DTSTART;TZID=America/Vancouver:20210301T022210\nRRULE:FREQ=DAILY;COUNT=30"
+ .parse()
+ .unwrap();
+
+ println!("{:?}", rrule.options);
+ println!("Found occurances: {:?}", rrule.all());
+ }
}