summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFredrik Meringdal <fmeringdal@hotmail.com>2020-10-17 17:48:22 +0200
committerFredrik Meringdal <fmeringdal@hotmail.com>2020-10-17 17:48:22 +0200
commit0ed916e47dfffe56f37ce52488160a5cc6718255 (patch)
tree078ea9393a535d7cc8f1c6699df9b57631e286d7
parenta02757e202926847ab04b7f7ec2861d3c19608e7 (diff)
downloadrust_rrule-0ed916e47dfffe56f37ce52488160a5cc6718255.zip
support for negative yearday
-rw-r--r--src/iter.rs4
-rw-r--r--src/options.rs4
-rw-r--r--tests/rrule.rs132
3 files changed, 111 insertions, 29 deletions
diff --git a/src/iter.rs b/src/iter.rs
index dd1066a..e556318 100644
--- a/src/iter.rs
+++ b/src/iter.rs
@@ -310,7 +310,7 @@ pub fn is_filtered(ii: &IterInfo, current_day: usize, options: &ParsedOptions) -
&& !includes(&options.bynmonthday, &ii.nmdaymask().unwrap()[current_day]))
|| (not_empty(&options.byyearday)
&& ((current_day < ii.yearlen().unwrap()
- && !includes(&options.byyearday, &(current_day + 1))
+ && !includes(&options.byyearday, &(current_day as isize + 1))
&& !includes(
&options.byyearday.iter().map(|v| *v as isize).collect(),
&(-(ii.yearlen().unwrap() as isize) + current_day as isize),
@@ -318,7 +318,7 @@ pub fn is_filtered(ii: &IterInfo, current_day: usize, options: &ParsedOptions) -
|| (current_day >= ii.yearlen().unwrap()
&& !includes(
&options.byyearday,
- &(current_day + 1 - ii.yearlen().unwrap()),
+ &((current_day + 1 - ii.yearlen().unwrap()) as isize),
)
&& !includes(
&options.byyearday.iter().map(|v| *v as isize).collect(),
diff --git a/src/options.rs b/src/options.rs
index 30143c1..9d037db 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -38,7 +38,7 @@ pub struct ParsedOptions {
pub bymonth: Vec<usize>,
pub bymonthday: Vec<usize>,
pub bynmonthday: Vec<isize>,
- pub byyearday: Vec<usize>,
+ pub byyearday: Vec<isize>,
pub byweekno: Vec<isize>,
pub byweekday: Vec<usize>,
pub byhour: Vec<usize>,
@@ -114,7 +114,7 @@ impl ParsedOptions {
self.bynmonthday = bynmonthday;
self
}
- pub fn byyearday(mut self, byyearday: Vec<usize>) -> Self {
+ pub fn byyearday(mut self, byyearday: Vec<isize>) -> Self {
self.byyearday = byyearday;
self
}
diff --git a/tests/rrule.rs b/tests/rrule.rs
index fd1fb7c..e15b714 100644
--- a/tests/rrule.rs
+++ b/tests/rrule.rs
@@ -44,24 +44,6 @@ mod test {
}
}
- #[ignore = "change options"]
- #[test]
- fn int_works() {
- let mut options = ParsedOptions::new(Frequenzy::WEEKLY, &ymd_hms(2012, 1, 1, 10, 30, 0))
- .interval(5)
- .count(3)
- .byweekday(vec![0, 4])
- .bymonth(vec![6]);
- test_recurring(
- &mut options,
- &vec![
- ymd_hms(2012, 6, 18, 10, 30, 0),
- ymd_hms(2012, 6, 22, 10, 30, 0),
- ymd_hms(2013, 6, 3, 10, 30, 0),
- ],
- );
- }
-
#[test]
fn yearly() {
let mut options =
@@ -491,9 +473,8 @@ mod test {
);
}
- #[ignore = "negative yeardays are not supported"]
#[test]
- fn yearly_by_yeardayneq() {
+ fn yearly_by_yeardayneg() {
let mut options = ParsedOptions {
freq: Frequenzy::YEARLY,
count: Some(4),
@@ -505,7 +486,7 @@ mod test {
byweekno: vec![],
byminute: vec![0],
bysecond: vec![0],
- byyearday: vec![365],
+ byyearday: vec![-365, -266, -166, -1],
bymonthday: vec![],
bynweekday: vec![],
bynmonthday: vec![],
@@ -1455,9 +1436,8 @@ mod test {
);
}
- #[ignore = "negative year day not supported yet"]
#[test]
- fn monthly_by_yearday_neg() {
+ fn monthly_by_yeardayneg() {
let mut options = ParsedOptions {
freq: Frequenzy::MONTHLY,
count: Some(4),
@@ -1469,8 +1449,7 @@ mod test {
byweekno: vec![],
byminute: vec![0],
bysecond: vec![0],
- //byyearday: vec![-365, -266, -166, -1],
- byyearday: vec![],
+ byyearday: vec![-365, -266, -166, -1],
bymonthday: vec![],
bynweekday: vec![],
bynmonthday: vec![],
@@ -2333,6 +2312,39 @@ mod test {
}
#[test]
+ fn weekly_by_yeardayneg() {
+ let mut options = ParsedOptions {
+ freq: Frequenzy::WEEKLY,
+ count: Some(4),
+ bymonth: vec![],
+ dtstart: ymd_hms(1997, 9, 2, 9, 0, 0),
+ byweekday: vec![],
+ byhour: vec![9],
+ bysetpos: vec![],
+ byweekno: vec![],
+ byminute: vec![0],
+ bysecond: vec![0],
+ byyearday: vec![-365, -266, -166, -1],
+ bymonthday: vec![],
+ bynweekday: vec![],
+ bynmonthday: vec![],
+ until: None,
+ wkst: 0,
+ tzid: None,
+ interval: 1,
+ };
+ test_recurring(
+ &mut options,
+ &vec![
+ ymd_hms(1997, 12, 31, 9, 0, 0),
+ ymd_hms(1998, 1, 1, 9, 0, 0),
+ ymd_hms(1998, 4, 10, 9, 0, 0),
+ ymd_hms(1998, 7, 19, 9, 0, 0),
+ ],
+ );
+ }
+
+ #[test]
fn weekly_by_month_yearday() {
let mut options = ParsedOptions {
freq: Frequenzy::WEEKLY,
@@ -3137,6 +3149,39 @@ mod test {
}
#[test]
+ fn daily_by_yeardayneg() {
+ let mut options = ParsedOptions {
+ freq: Frequenzy::DAILY,
+ count: Some(4),
+ bymonth: vec![],
+ dtstart: ymd_hms(1997, 9, 2, 9, 0, 0),
+ byweekday: vec![],
+ byhour: vec![9],
+ bysetpos: vec![],
+ byweekno: vec![],
+ byminute: vec![0],
+ bysecond: vec![0],
+ byyearday: vec![-365, -266, -166, -1],
+ bymonthday: vec![],
+ bynweekday: vec![],
+ bynmonthday: vec![],
+ until: None,
+ wkst: 0,
+ tzid: None,
+ interval: 1,
+ };
+ test_recurring(
+ &mut options,
+ &vec![
+ ymd_hms(1997, 12, 31, 9, 0, 0),
+ ymd_hms(1998, 1, 1, 9, 0, 0),
+ ymd_hms(1998, 4, 10, 9, 0, 0),
+ ymd_hms(1998, 7, 19, 9, 0, 0),
+ ],
+ );
+ }
+
+ #[test]
fn daily_by_month_and_yearday() {
let mut options = ParsedOptions {
freq: Frequenzy::DAILY,
@@ -3949,6 +3994,43 @@ mod test {
}
#[test]
+ fn hourly_by_yeardayneg() {
+ let mut options = ParsedOptions {
+ freq: Frequenzy::HOURLY,
+ count: Some(8),
+ bymonth: vec![],
+ dtstart: ymd_hms(1997, 9, 2, 9, 0, 0),
+ byweekday: vec![],
+ byhour: vec![],
+ bysetpos: vec![],
+ byweekno: vec![],
+ byminute: vec![0],
+ bysecond: vec![0],
+ byyearday: vec![-365, -266, -166, -1],
+ bymonthday: vec![],
+ bynweekday: vec![],
+ bynmonthday: vec![],
+ until: None,
+ wkst: 0,
+ tzid: None,
+ interval: 12,
+ };
+ test_recurring(
+ &mut options,
+ &vec![
+ ymd_hms(1997, 12, 31, 9, 0, 0),
+ ymd_hms(1997, 12, 31, 21, 0, 0),
+ ymd_hms(1998, 1, 1, 9, 0, 0),
+ ymd_hms(1998, 1, 1, 21, 0, 0),
+ ymd_hms(1998, 4, 10, 9, 0, 0),
+ ymd_hms(1998, 4, 10, 21, 0, 0),
+ ymd_hms(1998, 7, 19, 9, 0, 0),
+ ymd_hms(1998, 7, 19, 21, 0, 0),
+ ],
+ );
+ }
+
+ #[test]
fn hourly_by_month_and_yearday() {
let mut options = ParsedOptions {
freq: Frequenzy::HOURLY,