From 6a9c33a36255cf0f34f35446c22ea98434a566f0 Mon Sep 17 00:00:00 2001 From: Fredrik Meringdal Date: Sun, 25 Oct 2020 21:04:24 +0100 Subject: Progress on timezone support --- src/iter.rs | 45 +++----- src/iter_set.rs | 19 ++-- src/options.rs | 3 +- src/parse_options.rs | 11 +- src/poslist.rs | 9 +- src/rrule.rs | 4 +- src/rruleset.rs | 74 ++++-------- src/rrulestr.rs | 13 ++- tests/rrule.rs | 310 +++++++++++++++++++++++++-------------------------- 9 files changed, 229 insertions(+), 259 deletions(-) diff --git a/src/iter.rs b/src/iter.rs index 738cc26..6922ed4 100644 --- a/src/iter.rs +++ b/src/iter.rs @@ -2,17 +2,16 @@ use crate::datetime::*; use crate::iter_set::IterResult; use crate::iterinfo::*; use crate::options::*; -use crate::poslist::*; use crate::yearinfo::*; use chrono::prelude::*; use chrono::Duration; use chrono_tz::Tz; pub enum QueryMethodTypes { - ALL, - BETWEEN, - BEFORE, - AFTER, + All, + Between, + Before, + After, } pub struct IterArgs { @@ -34,17 +33,17 @@ pub struct RRuleIterRes { impl RRuleIterRes { pub fn new(method: QueryMethodTypes, args: IterArgs) -> Self { let (max_date, min_date) = match method { - QueryMethodTypes::BETWEEN if args.inc => { + QueryMethodTypes::Between if args.inc => { (Some(args.before.unwrap()), Some(args.after.unwrap())) } - QueryMethodTypes::BETWEEN => ( + QueryMethodTypes::Between => ( Some(args.before.unwrap() - Duration::milliseconds(1)), Some(args.after.unwrap() + Duration::milliseconds(1)), ), - QueryMethodTypes::BEFORE if args.inc => (Some(args.dt.unwrap()), None), - QueryMethodTypes::BEFORE => (Some(args.dt.unwrap() - Duration::milliseconds(1)), None), - QueryMethodTypes::AFTER if args.inc => (None, Some(args.dt.unwrap())), - QueryMethodTypes::AFTER => (None, Some(args.dt.unwrap() + Duration::milliseconds(1))), + QueryMethodTypes::Before if args.inc => (Some(args.dt.unwrap()), None), + QueryMethodTypes::Before => (Some(args.dt.unwrap() - Duration::milliseconds(1)), None), + QueryMethodTypes::After if args.inc => (None, Some(args.dt.unwrap())), + QueryMethodTypes::After => (None, Some(args.dt.unwrap() + Duration::milliseconds(1))), _ => (None, None), }; @@ -71,11 +70,11 @@ impl IterResult for RRuleIterRes { let too_late = self.max_date.is_some() && date > self.max_date.unwrap(); match self.method { - QueryMethodTypes::BETWEEN if too_early => true, - QueryMethodTypes::BETWEEN if too_late => false, - QueryMethodTypes::BEFORE if too_late => false, - QueryMethodTypes::AFTER if too_early => true, - QueryMethodTypes::AFTER => { + QueryMethodTypes::Between if too_early => true, + QueryMethodTypes::Between if too_late => false, + QueryMethodTypes::Before if too_late => false, + QueryMethodTypes::After if too_early => true, + QueryMethodTypes::After => { self.add(date); false } @@ -86,7 +85,7 @@ impl IterResult for RRuleIterRes { // before and after returns only one date whereas all and between an array fn get_value(&self) -> Vec> { match self.method { - QueryMethodTypes::BETWEEN | QueryMethodTypes::ALL => self.result.clone(), + QueryMethodTypes::Between | QueryMethodTypes::All => self.result.clone(), _ => { if self.result.is_empty() { return vec![]; @@ -232,11 +231,7 @@ pub fn remove_filtered_days( pub fn build_timeset(options: &ParsedOptions) -> Vec