pub trait DateTransitions: Sized {
Show 20 methods
// Required methods
fn is_leap_year(&self) -> bool;
fn last_day_of_month(&self) -> u32;
fn start_of_year(&self) -> Option<Self>;
fn end_of_year(&self) -> Option<Self>;
fn start_of_month(&self) -> Option<Self>;
fn end_of_month(&self) -> Option<Self>;
fn start_of_iso8601_week(&self) -> Option<Self>;
fn end_of_iso8601_week(&self) -> Option<Self>;
fn start_of_pred_year(&self) -> Option<Self>;
fn end_of_pred_year(&self) -> Option<Self>;
fn start_of_pred_month(&self) -> Option<Self>;
fn end_of_pred_month(&self) -> Option<Self>;
fn start_of_pred_iso8601_week(&self) -> Option<Self>;
fn end_of_pred_iso8601_week(&self) -> Option<Self>;
fn start_of_succ_year(&self) -> Option<Self>;
fn end_of_succ_year(&self) -> Option<Self>;
fn start_of_succ_month(&self) -> Option<Self>;
fn end_of_succ_month(&self) -> Option<Self>;
fn start_of_succ_iso8601_week(&self) -> Option<Self>;
fn end_of_succ_iso8601_week(&self) -> Option<Self>;
}Expand description
Common set of methods for transitioning dates into newer ones
Required Methods§
Sourcefn is_leap_year(&self) -> bool
fn is_leap_year(&self) -> bool
Returns true if leap year
Sourcefn last_day_of_month(&self) -> u32
fn last_day_of_month(&self) -> u32
Returns the last day of the month
Sourcefn start_of_year(&self) -> Option<Self>
fn start_of_year(&self) -> Option<Self>
Returns the date as on the start of the current year
Sourcefn end_of_year(&self) -> Option<Self>
fn end_of_year(&self) -> Option<Self>
Returns the date as on the end of the current year
Sourcefn start_of_month(&self) -> Option<Self>
fn start_of_month(&self) -> Option<Self>
Returns the date as on the start of the current month
Sourcefn end_of_month(&self) -> Option<Self>
fn end_of_month(&self) -> Option<Self>
Returns the date as on the end of the current month
Sourcefn start_of_iso8601_week(&self) -> Option<Self>
fn start_of_iso8601_week(&self) -> Option<Self>
Returns the date as on the start of the current week
Sourcefn end_of_iso8601_week(&self) -> Option<Self>
fn end_of_iso8601_week(&self) -> Option<Self>
Returns the date as on the end of the current week
Sourcefn start_of_pred_year(&self) -> Option<Self>
fn start_of_pred_year(&self) -> Option<Self>
Returns the date as on the start of the previous year
Sourcefn end_of_pred_year(&self) -> Option<Self>
fn end_of_pred_year(&self) -> Option<Self>
Returns the date as on the end of the previous year
Sourcefn start_of_pred_month(&self) -> Option<Self>
fn start_of_pred_month(&self) -> Option<Self>
Returns the date as on the start of the previous month
Sourcefn end_of_pred_month(&self) -> Option<Self>
fn end_of_pred_month(&self) -> Option<Self>
Returns the date as on the end of the previous month
Sourcefn start_of_pred_iso8601_week(&self) -> Option<Self>
fn start_of_pred_iso8601_week(&self) -> Option<Self>
Returns the date as on the start of the previous week
Sourcefn end_of_pred_iso8601_week(&self) -> Option<Self>
fn end_of_pred_iso8601_week(&self) -> Option<Self>
Returns the date as on the end of the previous week
Sourcefn start_of_succ_year(&self) -> Option<Self>
fn start_of_succ_year(&self) -> Option<Self>
Returns the date as on the start of the succeeding year
Sourcefn end_of_succ_year(&self) -> Option<Self>
fn end_of_succ_year(&self) -> Option<Self>
Returns the date as on the end of the succeeding year
Sourcefn start_of_succ_month(&self) -> Option<Self>
fn start_of_succ_month(&self) -> Option<Self>
Returns the date as on the start of the succeeding month
Sourcefn end_of_succ_month(&self) -> Option<Self>
fn end_of_succ_month(&self) -> Option<Self>
Returns the date as on the end of the succeeding month
Sourcefn start_of_succ_iso8601_week(&self) -> Option<Self>
fn start_of_succ_iso8601_week(&self) -> Option<Self>
Returns the date as on the start of the succeeding week
Sourcefn end_of_succ_iso8601_week(&self) -> Option<Self>
fn end_of_succ_iso8601_week(&self) -> Option<Self>
Returns the date as on the end of the succeeding week
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl DateTransitions for NaiveDate
impl DateTransitions for NaiveDate
Source§fn is_leap_year(&self) -> bool
fn is_leap_year(&self) -> bool
Returns true if the date belongs to a year which is leap.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(1996, 8, 14);
assert_eq!(d1.is_leap_year(), true);
let d2 = NaiveDate::from_ymd(1900, 2, 28);
assert_eq!(d2.is_leap_year(), false);
let d3 = NaiveDate::from_ymd(2000, 2, 29);
assert_eq!(d3.is_leap_year(), true);
let d4 = NaiveDate::from_ymd(1997, 11, 3);
assert_eq!(d4.is_leap_year(), false);Source§fn last_day_of_month(&self) -> u32
fn last_day_of_month(&self) -> u32
Returns the last day of the month
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(1996, 2, 23);
assert_eq!(d1.last_day_of_month(), 29);
let d2 = NaiveDate::from_ymd(1993, 2, 1);
assert_eq!(d2.last_day_of_month(), 28);
let d3 = NaiveDate::from_ymd(2000, 1, 1);
assert_eq!(d3.last_day_of_month(), 31);Source§fn start_of_year(&self) -> Option<Self>
fn start_of_year(&self) -> Option<Self>
Returns the year start date for the current date
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 3, 31);
assert_eq!(d.start_of_year().unwrap(), NaiveDate::from_ymd(2019, 1, 1));Source§fn end_of_year(&self) -> Option<Self>
fn end_of_year(&self) -> Option<Self>
Returns the year end date for the current date
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 3, 31);
assert_eq!(d.end_of_year().unwrap(), NaiveDate::from_ymd(2019, 12, 31));Source§fn start_of_month(&self) -> Option<Self>
fn start_of_month(&self) -> Option<Self>
Returns the start date of the current month
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 9, 13);
assert_eq!(d.start_of_month().unwrap(), NaiveDate::from_ymd(2019, 9, 1));Source§fn end_of_month(&self) -> Option<Self>
fn end_of_month(&self) -> Option<Self>
Returns the date as on the end of the current month
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(1996, 2, 23);
assert_eq!(d1.end_of_month().unwrap(), NaiveDate::from_ymd(1996, 2, 29));
let d2 = NaiveDate::from_ymd(1993, 2, 1);
assert_eq!(d2.end_of_month().unwrap(), NaiveDate::from_ymd(1993, 2, 28));
let d3 = NaiveDate::from_ymd(2000, 1, 1);
assert_eq!(d3.end_of_month().unwrap(), NaiveDate::from_ymd(2000, 1, 31));Source§fn start_of_iso8601_week(&self) -> Option<Self>
fn start_of_iso8601_week(&self) -> Option<Self>
Returns the start of the week for the current date. Uses the ISO 8601 standard for calculating the week. See Wikipedia.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2020, 1, 2);
assert_eq!(d1.start_of_iso8601_week().unwrap(), NaiveDate::from_ymd(2019, 12, 30));
let d2 = NaiveDate::from_ymd(2019, 12, 29);
assert_eq!(d2.start_of_iso8601_week().unwrap(), NaiveDate::from_ymd(2019, 12, 23));
let d3 = NaiveDate::from_ymd(1992, 2, 29);
assert_eq!(d3.start_of_iso8601_week().unwrap(), NaiveDate::from_ymd(1992, 2, 24));Source§fn end_of_iso8601_week(&self) -> Option<Self>
fn end_of_iso8601_week(&self) -> Option<Self>
Returns the end of the week for the current date. Uses the ISO 8601 standard for calculating the week. See Wikipedia.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2020, 1, 2);
assert_eq!(d1.end_of_iso8601_week().unwrap(), NaiveDate::from_ymd(2020, 1, 5));
let d2 = NaiveDate::from_ymd(2019, 12, 29);
assert_eq!(d2.end_of_iso8601_week().unwrap(), NaiveDate::from_ymd(2019, 12, 29));
let d3 = NaiveDate::from_ymd(1992, 2, 29);
assert_eq!(d3.end_of_iso8601_week().unwrap(), NaiveDate::from_ymd(1992, 3, 1));Source§fn start_of_pred_year(&self) -> Option<Self>
fn start_of_pred_year(&self) -> Option<Self>
Returns the start of preceding year relative to the current date
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 3, 31);
assert_eq!(d.start_of_pred_year().unwrap(), NaiveDate::from_ymd(2018, 1, 1));Source§fn end_of_pred_year(&self) -> Option<Self>
fn end_of_pred_year(&self) -> Option<Self>
Returns the end of preceding year relative to the current date
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 3, 31);
assert_eq!(d.end_of_pred_year().unwrap(), NaiveDate::from_ymd(2018, 12, 31));Source§fn start_of_pred_month(&self) -> Option<Self>
fn start_of_pred_month(&self) -> Option<Self>
Returns the start of preceding month for the current date.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 1, 4);
assert_eq!(d1.start_of_pred_month().unwrap(), NaiveDate::from_ymd(2018, 12, 1));
let d2 = NaiveDate::from_ymd(1999, 11, 17);
assert_eq!(d2.start_of_pred_month().unwrap(), NaiveDate::from_ymd(1999, 10, 1));Source§fn end_of_pred_month(&self) -> Option<Self>
fn end_of_pred_month(&self) -> Option<Self>
Returns the end of preceding month for the current date.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 1, 4);
assert_eq!(d1.end_of_pred_month().unwrap(), NaiveDate::from_ymd(2018, 12, 31));
let d2 = NaiveDate::from_ymd(1999, 10, 17);
assert_eq!(d2.end_of_pred_month().unwrap(), NaiveDate::from_ymd(1999, 9, 30));
let d3 = NaiveDate::from_ymd(1996, 3, 1);
assert_eq!(d3.end_of_pred_month().unwrap(), NaiveDate::from_ymd(1996, 2, 29));Source§fn start_of_pred_iso8601_week(&self) -> Option<Self>
fn start_of_pred_iso8601_week(&self) -> Option<Self>
Returns the start of preceding week for the current date. Uses the ISO 8601 standard for calculating the week. See Wikipedia.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 1, 4);
assert_eq!(d1.start_of_pred_iso8601_week().unwrap(), NaiveDate::from_ymd(2018, 12, 24));
let d2 = NaiveDate::from_ymd(1999, 10, 17);
assert_eq!(d2.start_of_pred_iso8601_week().unwrap(), NaiveDate::from_ymd(1999, 10, 4));
let d3 = NaiveDate::from_ymd(1996, 3, 1);
assert_eq!(d3.start_of_pred_iso8601_week().unwrap(), NaiveDate::from_ymd(1996, 2, 19));Source§fn end_of_pred_iso8601_week(&self) -> Option<Self>
fn end_of_pred_iso8601_week(&self) -> Option<Self>
Returns the end of preceding week for the current date. Uses the ISO 8601 standard for calculating the week. See Wikipedia.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 1, 4);
assert_eq!(d1.end_of_pred_iso8601_week().unwrap(), NaiveDate::from_ymd(2018, 12, 30));
let d2 = NaiveDate::from_ymd(1999, 10, 17);
assert_eq!(d2.end_of_pred_iso8601_week().unwrap(), NaiveDate::from_ymd(1999, 10, 10));
let d3 = NaiveDate::from_ymd(1996, 3, 1);
assert_eq!(d3.end_of_pred_iso8601_week().unwrap(), NaiveDate::from_ymd(1996, 2, 25));Source§fn start_of_succ_year(&self) -> Option<Self>
fn start_of_succ_year(&self) -> Option<Self>
Returns the start of succeeding year relative to the current date
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 3, 31);
assert_eq!(d.start_of_succ_year().unwrap(), NaiveDate::from_ymd(2020, 1, 1));Source§fn end_of_succ_year(&self) -> Option<Self>
fn end_of_succ_year(&self) -> Option<Self>
Returns the end of succeeding year relative to the current date
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d = NaiveDate::from_ymd(2019, 3, 31);
assert_eq!(d.end_of_succ_year().unwrap(), NaiveDate::from_ymd(2020, 12, 31));Source§fn start_of_succ_month(&self) -> Option<Self>
fn start_of_succ_month(&self) -> Option<Self>
Returns the start of succeeding month for the current date.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 12, 12);
assert_eq!(d1.start_of_succ_month().unwrap(), NaiveDate::from_ymd(2020, 1, 1));
let d2 = NaiveDate::from_ymd(1999, 2, 28);
assert_eq!(d2.start_of_succ_month().unwrap(), NaiveDate::from_ymd(1999, 3, 1));Source§fn end_of_succ_month(&self) -> Option<Self>
fn end_of_succ_month(&self) -> Option<Self>
Returns the end of succeeding month for the current date.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 1, 4);
assert_eq!(d1.end_of_pred_month().unwrap(), NaiveDate::from_ymd(2018, 12, 31));
let d2 = NaiveDate::from_ymd(1999, 10, 17);
assert_eq!(d2.end_of_pred_month().unwrap(), NaiveDate::from_ymd(1999, 9, 30));
let d3 = NaiveDate::from_ymd(1996, 3, 1);
assert_eq!(d3.end_of_pred_month().unwrap(), NaiveDate::from_ymd(1996, 2, 29));Source§fn start_of_succ_iso8601_week(&self) -> Option<Self>
fn start_of_succ_iso8601_week(&self) -> Option<Self>
Returns the start of succeeding week for the current date. Uses the ISO 8601 standard for calculating the week. See Wikipedia.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2020, 1, 4);
assert_eq!(d1.start_of_succ_iso8601_week().unwrap(), NaiveDate::from_ymd(2020, 1, 6));
let d2 = NaiveDate::from_ymd(2017, 12, 28);
assert_eq!(d2.start_of_succ_iso8601_week().unwrap(), NaiveDate::from_ymd(2018, 1, 1));
let d3 = NaiveDate::from_ymd(1996, 2, 26);
assert_eq!(d3.start_of_succ_iso8601_week().unwrap(), NaiveDate::from_ymd(1996, 3, 4));Source§fn end_of_succ_iso8601_week(&self) -> Option<Self>
fn end_of_succ_iso8601_week(&self) -> Option<Self>
Returns the end of succeeding week for the current date. Uses the ISO 8601 standard for calculating the week. See Wikipedia.
§Example
use chrono::NaiveDate;
use chrono_utilities::naive::DateTransitions;
let d1 = NaiveDate::from_ymd(2019, 1, 4);
assert_eq!(d1.end_of_succ_iso8601_week().unwrap(), NaiveDate::from_ymd(2019, 1, 13));
let d2 = NaiveDate::from_ymd(2004, 2, 20);
assert_eq!(d2.end_of_succ_iso8601_week().unwrap(), NaiveDate::from_ymd(2004, 2, 29));
let d3 = NaiveDate::from_ymd(2005, 12, 20);
assert_eq!(d3.end_of_succ_iso8601_week().unwrap(), NaiveDate::from_ymd(2006, 1, 1));