diff --git a/src/cli.rs b/src/cli.rs index b77fe23..25a91ac 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -2,7 +2,6 @@ // // SPDX-License-Identifier: MIT -use crate::utils::ChronoDate; use anyhow::{anyhow, Result}; use chrono::prelude::*; use clap::{crate_authors, crate_name, crate_version, Parser}; @@ -57,8 +56,8 @@ impl Default for Cli { } impl Cli { - pub fn validate_date(&self) -> Result { - let mut today: ChronoDate = Local::now().date_naive(); + pub fn validate_date(&self) -> Result { + let mut today: chrono::NaiveDate = Local::now().date_naive(); let mut year: i32 = today.year(); let mut month: u32 = today.month(); let mut day: u32 = today.day(); @@ -147,13 +146,13 @@ mod tests { #[test] fn test_validate_date_defaults_to_now() { - let today: ChronoDate = Local::now().date_naive(); + let today: chrono::NaiveDate = Local::now().date_naive(); let o: Cli = Cli::default(); assert_eq!(today, o.validate_date().unwrap()); } #[test] fn test_validate_date_default_to_now_with_custom_year() { - let today: ChronoDate = Local::now().date_naive().with_year(2007).unwrap(); + let today: chrono::NaiveDate = Local::now().date_naive().with_year(2007).unwrap(); let o: Cli = Cli { date: vec![String::from("2007")], ..Default::default() @@ -162,7 +161,7 @@ mod tests { } #[test] fn test_validate_date_defaults_to_now_with_custom_year_and_month() { - let today: ChronoDate = Local::now() + let today: chrono::NaiveDate = Local::now() .date_naive() .with_year(2007) .unwrap() @@ -176,7 +175,7 @@ mod tests { } #[test] fn test_validate_date_defaults_to_now_with_custom_year_and_month_and_day() { - let today: ChronoDate = Local::now() + let today: chrono::NaiveDate = Local::now() .date_naive() .with_year(2007) .unwrap() @@ -192,7 +191,7 @@ mod tests { } #[test] fn test_validate_date_defaults_to_now_with_ambiguous_arguments() { - let today: ChronoDate = Local::now().date_naive(); + let today: chrono::NaiveDate = Local::now().date_naive(); let o: Cli = Cli { date: vec![ String::from("2007"), @@ -266,7 +265,7 @@ mod tests { } #[test] fn test_validate_date_errors_with_non_existent_date() { - let today: ChronoDate = Local::now().date_naive(); + let today: chrono::NaiveDate = Local::now().date_naive(); let o: Cli = Cli { date: vec![String::from("2007"), String::from("2"), String::from("30")], ..Default::default() diff --git a/src/context.rs b/src/context.rs index 9856cfb..5e9cf1d 100644 --- a/src/context.rs +++ b/src/context.rs @@ -6,14 +6,13 @@ use crate::cli::Cli; use crate::config::{Config, Theme}; use crate::config::{Style, StyleType}; use crate::events::Event; -use crate::utils::ChronoDate; use anyhow::Result; use chrono::prelude::*; use clap::Parser; // A struct storing the combined settings of config file, theme, options, ... pub struct Context { - pub usersetdate: ChronoDate, + pub usersetdate: chrono::NaiveDate, pub opts: Cli, pub config: Config, pub eventstuple: Vec<(Event, Style)>, @@ -37,7 +36,7 @@ impl Context { StyleType::Light }; - let usersetdate: ChronoDate = match opts.validate_date() { + let usersetdate: chrono::NaiveDate = match opts.validate_date() { Ok(x) => x, Err(x) => return Err(x), }; diff --git a/src/events/mod.rs b/src/events/mod.rs index 37ced4b..5202485 100644 --- a/src/events/mod.rs +++ b/src/events/mod.rs @@ -5,7 +5,6 @@ mod ics; pub use ics::ReadFromIcsFile; -use crate::utils::ChronoDate; use chrono::prelude::*; use rrule::{RRuleSet, Tz}; use std::fmt; @@ -16,7 +15,7 @@ pub enum EventDateTime { date_time: chrono::NaiveDateTime, offset: Option, }, - Date(ChronoDate), + Date(chrono::NaiveDate), } impl EventDateTime { @@ -50,11 +49,15 @@ impl Default for Event { } impl Event { - pub fn is_day(&self, date: &ChronoDate) -> bool { + pub fn is_day(&self, date: &chrono::NaiveDate) -> bool { self.in_range(*date, *date) } - pub fn in_range(&self, daterangebegin: ChronoDate, daterangeend: ChronoDate) -> bool { + pub fn in_range( + &self, + daterangebegin: chrono::NaiveDate, + daterangeend: chrono::NaiveDate, + ) -> bool { let timezone: Tz = Local::now().timezone().into(); let before = timezone .with_ymd_and_hms( diff --git a/src/main.rs b/src/main.rs index 1664377..a8d745f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,12 +21,12 @@ use events::{Events, ReadFromIcsFile}; use output::agenda::Agenda; use output::calendar::Calendar; use output::date::Date; -use utils::{ChronoDate, DateExtensions}; +use utils::DateExtensions; #[cfg(not(tarpaulin_include))] fn main() { let mut columns = 1; - let mut months: Vec = vec![]; + let mut months: Vec = vec![]; let mut ctx: Context; match Context::new() { @@ -37,8 +37,8 @@ fn main() { } } - let mut daterangebegin: ChronoDate = ctx.usersetdate.first_day_of_month(); - let mut daterangeend: ChronoDate = ctx.usersetdate.last_day_of_month(); + let mut daterangebegin: chrono::NaiveDate = ctx.usersetdate.first_day_of_month(); + let mut daterangeend: chrono::NaiveDate = ctx.usersetdate.last_day_of_month(); if ctx.opts.three { daterangebegin = (ctx.usersetdate - Duration::weeks(4)).first_day_of_month(); diff --git a/src/output/calendar.rs b/src/output/calendar.rs index 81cd556..dffd4c8 100644 --- a/src/output/calendar.rs +++ b/src/output/calendar.rs @@ -2,7 +2,7 @@ // // SPDX-License-Identifier: MIT -use crate::utils::{ChronoDate, DateExtensions, MonthFullWeeksIter}; +use crate::utils::{DateExtensions, MonthFullWeeksIter}; use crate::Context; use crate::Date; use chrono::{Duration, NaiveDate}; @@ -10,7 +10,7 @@ use chrono::{Duration, NaiveDate}; use std::fmt; pub struct Calendar<'a> { - pub dates: Vec, + pub dates: Vec, pub columns: usize, pub ctx: &'a Context, } @@ -93,7 +93,7 @@ impl fmt::Display for Calendar<'_> { impl Calendar<'_> { fn weekdays(&self) -> String { - let mut week: Vec = vec![]; + let mut week: Vec = vec![]; let (s, e) = if self.ctx.opts.sunday { (3, 9) } else { @@ -172,7 +172,7 @@ mod tests { }; ctx.opts.year = true; - let mut dates: Vec = vec![]; + let mut dates: Vec = vec![]; let daterangebegin = ctx.usersetdate.first_day_of_year(); let daterangeend = ctx.usersetdate.last_day_of_year(); let mut tmpdate = daterangebegin; diff --git a/src/output/date.rs b/src/output/date.rs index 2e33926..68e4e91 100644 --- a/src/output/date.rs +++ b/src/output/date.rs @@ -3,16 +3,16 @@ // SPDX-License-Identifier: MIT use crate::config::{DateProperty, Style, StyleType}; -use crate::utils::{convertstyle, ChronoDate, DateExtensions}; +use crate::utils::{convertstyle, DateExtensions}; use crate::Context; use chrono::Datelike; use std::fmt; pub struct Date<'a> { - pub date: ChronoDate, + pub date: chrono::NaiveDate, pub ctx: &'a Context, - pub firstdayofdisplayedmonth: ChronoDate, + pub firstdayofdisplayedmonth: chrono::NaiveDate, } impl Date<'_> { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index fc23985..bc163ff 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -4,8 +4,6 @@ mod date_extensions; mod helpers; -mod types; pub use date_extensions::{DateExtensions, DateRange, MonthFullWeeksIter}; pub use helpers::convertstyle; -pub use types::ChronoDate; diff --git a/src/utils/types.rs b/src/utils/types.rs deleted file mode 100644 index e9fdd47..0000000 --- a/src/utils/types.rs +++ /dev/null @@ -1,5 +0,0 @@ -// SPDX-FileCopyrightText: 2021-2023 Birger Schacht -// -// SPDX-License-Identifier: MIT - -pub type ChronoDate = chrono::NaiveDate;