From 2c70b134b5d6bd8a49749fed348ae0e6958f8455 Mon Sep 17 00:00:00 2001 From: Fredrik Meringdal Date: Wed, 16 Dec 2020 16:32:26 +0100 Subject: numeric identifier when n=1 bug --- src/options.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'src/options.rs') diff --git a/src/options.rs b/src/options.rs index ac35315..7f291bc 100644 --- a/src/options.rs +++ b/src/options.rs @@ -17,19 +17,25 @@ pub enum Frequenzy { Secondly = 6, } +#[derive(Copy, Clone, Debug, PartialEq)] +pub enum NWeekdayIdentifier { + Every, + Identifier(isize), +} + #[derive(Copy, Clone, Debug)] pub struct NWeekday { pub weekday: usize, - pub n: isize, + pub n: NWeekdayIdentifier, } impl NWeekday { - pub fn new(weekday: usize, n: isize) -> Self { + pub fn new(weekday: usize, n: NWeekdayIdentifier) -> Self { // if (n === 0) throw new Error("Can't create weekday with n == 0") Self { weekday, n } } - pub fn from(weekday: &Weekday, n: isize) -> Self { + pub fn from(weekday: &Weekday, n: NWeekdayIdentifier) -> Self { // if (n === 0) throw new Error("Can't create weekday with n == 0") Self { weekday: get_weekday_val(weekday), @@ -37,7 +43,7 @@ impl NWeekday { } } - pub fn nth(&self, n: isize) -> Self { + pub fn nth(&self, n: NWeekdayIdentifier) -> Self { if self.n == n { return self.clone(); } @@ -235,7 +241,7 @@ impl Options { let byweekday = byweekday .iter() .map(|w| get_weekday_val(w)) - .map(|w| NWeekday::new(w, 1)) + .map(|w| NWeekday::new(w, NWeekdayIdentifier::Every)) .collect(); self.byweekday = Some(byweekday); self -- cgit v1.2.3