diff options
Diffstat (limited to 'src/datetime.rs')
-rw-r--r-- | src/datetime.rs | 23 |
1 files changed, 23 insertions, 0 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, |