summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/datetime.rs23
-rw-r--r--src/iter/easter.rs (renamed from src/easter.rs)0
-rw-r--r--src/iter/iterinfo.rs6
-rw-r--r--src/iter/masks.rs (renamed from src/masks.rs)0
-rw-r--r--src/iter/mod.rs9
-rw-r--r--src/iter/monthinfo.rs2
-rw-r--r--src/iter/poslist.rs2
-rw-r--r--src/iter/utils.rs8
-rw-r--r--src/iter/yearinfo.rs37
-rw-r--r--src/lib.rs2
-rw-r--r--src/options.rs2
-rw-r--r--src/parse_options.rs2
12 files changed, 46 insertions, 47 deletions
diff --git a/src/datetime.rs b/src/datetime.rs
index 2e06d24..69cfb00 100644
--- a/src/datetime.rs
+++ b/src/datetime.rs
@@ -14,6 +14,29 @@ pub fn to_ordinal(date: &DateTime<Utc>) -> isize {
(date.timestamp() / 60 / 60 / 24) as isize
}
+pub fn is_leap_year(year: i32) -> bool {
+ year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
+}
+
+pub fn get_year_len(year: i32) -> usize {
+ if is_leap_year(year) {
+ return 366;
+ }
+ 365
+}
+
+pub fn get_weekday_val(wk: &Weekday) -> usize {
+ match wk {
+ Weekday::Mon => 0,
+ Weekday::Tue => 1,
+ Weekday::Wed => 2,
+ Weekday::Thu => 3,
+ Weekday::Fri => 4,
+ Weekday::Sat => 5,
+ Weekday::Sun => 6,
+ }
+}
+
#[derive(Debug)]
pub struct Time {
pub hour: usize,
diff --git a/src/easter.rs b/src/iter/easter.rs
index b41b270..b41b270 100644
--- a/src/easter.rs
+++ b/src/iter/easter.rs
diff --git a/src/iter/iterinfo.rs b/src/iter/iterinfo.rs
index 09090f1..1d401dd 100644
--- a/src/iter/iterinfo.rs
+++ b/src/iter/iterinfo.rs
@@ -1,8 +1,8 @@
-use crate::datetime::*;
-use crate::easter::*;
+use crate::datetime::{Time, to_ordinal};
+use crate::iter::easter::easter;
use crate::iter::monthinfo::{MonthInfo, rebuild_month};
use crate::iter::yearinfo::{YearInfo, rebuild_year};
-use crate::options::*;
+use crate::options::{ParsedOptions, Frequenzy};
use chrono::prelude::*;
pub struct IterInfo<'a> {
diff --git a/src/masks.rs b/src/iter/masks.rs
index 8b2f6b0..8b2f6b0 100644
--- a/src/masks.rs
+++ b/src/iter/masks.rs
diff --git a/src/iter/mod.rs b/src/iter/mod.rs
index d426a98..42cf58f 100644
--- a/src/iter/mod.rs
+++ b/src/iter/mod.rs
@@ -1,16 +1,15 @@
mod yearinfo;
-use yearinfo::get_weekday_val;
-
mod monthinfo;
-
mod iterinfo;
use iterinfo::IterInfo;
-
mod poslist;
use poslist::build_poslist;
+mod easter;
+mod masks;
+mod utils;
use crate::options::*;
-use crate::datetime::{Time, from_ordinal};
+use crate::datetime::{Time, from_ordinal, get_weekday_val};
use chrono::offset::TimeZone;
use chrono::prelude::*;
use chrono::{DateTime, Duration};
diff --git a/src/iter/monthinfo.rs b/src/iter/monthinfo.rs
index c89bfc3..9da2ca6 100644
--- a/src/iter/monthinfo.rs
+++ b/src/iter/monthinfo.rs
@@ -1,5 +1,5 @@
use crate::options::*;
-use crate::iter::yearinfo::pymod;
+use crate::iter::utils::pymod;
#[derive(Debug)]
pub struct MonthInfo {
diff --git a/src/iter/poslist.rs b/src/iter/poslist.rs
index fa9fbd8..421d352 100644
--- a/src/iter/poslist.rs
+++ b/src/iter/poslist.rs
@@ -1,6 +1,6 @@
use crate::datetime::*;
use crate::iter::iterinfo::IterInfo;
-use crate::iter::yearinfo::pymod;
+use crate::iter::utils::pymod;
use crate::datetime::from_ordinal;
use chrono::prelude::*;
use chrono_tz::Tz;
diff --git a/src/iter/utils.rs b/src/iter/utils.rs
new file mode 100644
index 0000000..c168c92
--- /dev/null
+++ b/src/iter/utils.rs
@@ -0,0 +1,8 @@
+pub fn pymod(a: isize, b: isize) -> isize {
+ let r = a % b;
+ // If r and b differ in sign, add b to wrap the result to the correct sign.
+ if (r > 0 && b < 0) || (r < 0 && b > 0) {
+ return r + b;
+ }
+ r
+} \ No newline at end of file
diff --git a/src/iter/yearinfo.rs b/src/iter/yearinfo.rs
index 8a944f7..40b48ce 100644
--- a/src/iter/yearinfo.rs
+++ b/src/iter/yearinfo.rs
@@ -1,7 +1,8 @@
-use crate::masks::MASKS;
+use crate::iter::masks::MASKS;
use crate::options::*;
use chrono::prelude::*;
-use crate::datetime::to_ordinal;
+use crate::datetime::{to_ordinal, get_year_len, get_weekday_val};
+use crate::iter::utils::pymod;
#[derive(Debug)]
@@ -18,29 +19,6 @@ pub struct YearInfo {
pub wnomask: Option<Vec<usize>>,
}
-fn is_leap_year(year: i32) -> bool {
- year % 4 == 0 && (year % 100 != 0 || year % 400 == 0)
-}
-
-fn get_year_len(year: i32) -> usize {
- if is_leap_year(year) {
- return 366;
- }
- 365
-}
-
-pub fn get_weekday_val(wk: &Weekday) -> usize {
- match wk {
- Weekday::Mon => 0,
- Weekday::Tue => 1,
- Weekday::Wed => 2,
- Weekday::Thu => 3,
- Weekday::Fri => 4,
- Weekday::Sat => 5,
- Weekday::Sun => 6,
- }
-}
-
pub struct BaseMasks {
mmask: Vec<usize>,
mdaymask: Vec<isize>,
@@ -74,15 +52,6 @@ fn base_year_masks(year: i32) -> BaseMasks {
}
}
-pub fn pymod(a: isize, b: isize) -> isize {
- let r = a % b;
- // If r and b differ in sign, add b to wrap the result to the correct sign.
- if (r > 0 && b < 0) || (r < 0 && b > 0) {
- return r + b;
- }
- r
-}
-
pub fn rebuild_year(year: i32, options: &ParsedOptions) -> YearInfo {
let firstyday = Utc.ymd(year, 1, 1).and_hms_milli(0, 0, 0, 0);
diff --git a/src/lib.rs b/src/lib.rs
index 17d9ce1..6740b10 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -38,9 +38,7 @@ extern crate once_cell;
extern crate regex;
mod datetime;
-mod easter;
mod iter;
-mod masks;
mod parse_options;
mod options;
mod rrulestr;
diff --git a/src/options.rs b/src/options.rs
index 2bface8..5599454 100644
--- a/src/options.rs
+++ b/src/options.rs
@@ -35,6 +35,7 @@ pub struct ParsedOptions {
pub byeaster: Option<isize>,
}
+// TODO: PartialOptions shouldnt have all of these fields
#[derive(Debug, Clone)]
pub struct PartialOptions {
pub freq: Option<Frequenzy>,
@@ -83,6 +84,7 @@ impl PartialOptions {
}
}
+ // TODO: better name
fn is_some_or_none<'a, T>(prop1: &'a Option<T>, prop2: &'a Option<T>) -> &'a Option<T> {
if prop2.is_some() {
return prop2;
diff --git a/src/parse_options.rs b/src/parse_options.rs
index 2df90be..b7926ef 100644
--- a/src/parse_options.rs
+++ b/src/parse_options.rs
@@ -2,7 +2,7 @@ use chrono::prelude::*;
use crate::options::{ParsedOptions, Frequenzy, PartialOptions};
use chrono_tz::{Tz, UTC};
-// TODO: make this method on partialoptions struct
+// TODO: Validation
pub fn parse_options(options: &PartialOptions) -> ParsedOptions {
let mut default_partial_options = PartialOptions::new();
default_partial_options.interval = Some(1);