From 5d16648df4a49a3d6cac411a973985b7d5f69ca2 Mon Sep 17 00:00:00 2001 From: Brandon W Maister Date: Mon, 23 Dec 2019 17:33:44 -0500 Subject: [PATCH] rename from_ymwd -> from_weekday_of_month --- CHANGELOG.md | 2 +- src/naive/date.rs | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f22a3b..41c1e89 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ Versions with only mechnical changes will be omitted from the following list. ### Features -* Added `NaiveDate::from_ymwd{,_opt}` for getting eg. the 2nd Friday of March 2017. +* Added `NaiveDate::from_weekday_of_month{,_opt}` for getting eg. the 2nd Friday of March 2017. ## 0.4.5 diff --git a/src/naive/date.rs b/src/naive/date.rs index a7005fd..ecf5f27 100644 --- a/src/naive/date.rs +++ b/src/naive/date.rs @@ -409,7 +409,7 @@ impl NaiveDate { /// Makes a new `NaiveDate` by counting the number of occurances of a particular day-of-week /// since the beginning of the given month. For instance, if you want the 2nd Friday of March - /// 2017, you would use `NaiveDate::from_ymwd(2017, 3, Weekday::Fri, 2)`. + /// 2017, you would use `NaiveDate::from_weekday_of_month(2017, 3, Weekday::Fri, 2)`. /// /// # Panics /// @@ -423,32 +423,32 @@ impl NaiveDate { /// ~~~~ /// use chrono::{NaiveDate, Weekday}; /// - /// let from_ymwd = NaiveDate::from_ymwd; + /// let from_weekday_of_month = NaiveDate::from_weekday_of_month; /// let from_ymd = NaiveDate::from_ymd; /// - /// assert_eq!(from_ymwd(2018, 8, Weekday::Wed, 1), from_ymd(2018, 8, 1)); - /// assert_eq!(from_ymwd(2018, 8, Weekday::Fri, 1), from_ymd(2018, 8, 3)); - /// assert_eq!(from_ymwd(2018, 8, Weekday::Tue, 2), from_ymd(2018, 8, 14)); - /// assert_eq!(from_ymwd(2018, 8, Weekday::Fri, 4), from_ymd(2018, 8, 24)); - /// assert_eq!(from_ymwd(2018, 8, Weekday::Fri, 5), from_ymd(2018, 8, 31)); + /// assert_eq!(from_weekday_of_month(2018, 8, Weekday::Wed, 1), from_ymd(2018, 8, 1)); + /// assert_eq!(from_weekday_of_month(2018, 8, Weekday::Fri, 1), from_ymd(2018, 8, 3)); + /// assert_eq!(from_weekday_of_month(2018, 8, Weekday::Tue, 2), from_ymd(2018, 8, 14)); + /// assert_eq!(from_weekday_of_month(2018, 8, Weekday::Fri, 4), from_ymd(2018, 8, 24)); + /// assert_eq!(from_weekday_of_month(2018, 8, Weekday::Fri, 5), from_ymd(2018, 8, 31)); /// ~~~~ - pub fn from_ymwd(year: i32, month: u32, weekday: Weekday, n: u8) -> NaiveDate { - NaiveDate::from_ymwd_opt(year, month, weekday, n).expect("out-of-range date") + pub fn from_weekday_of_month(year: i32, month: u32, weekday: Weekday, n: u8) -> NaiveDate { + NaiveDate::from_weekday_of_month_opt(year, month, weekday, n).expect("out-of-range date") } /// Makes a new `NaiveDate` by counting the number of occurances of a particular day-of-week /// since the beginning of the given month. For instance, if you want the 2nd Friday of March - /// 2017, you would use `NaiveDate::from_ymwd(2017, 3, Weekday::Fri, 2)`. `n` is 1-indexed. + /// 2017, you would use `NaiveDate::from_weekday_of_month(2017, 3, Weekday::Fri, 2)`. `n` is 1-indexed. /// /// ~~~~ /// use chrono::{NaiveDate, Weekday}; - /// assert_eq!(NaiveDate::from_ymwd_opt(2017, 3, Weekday::Fri, 2), + /// assert_eq!(NaiveDate::from_weekday_of_month_opt(2017, 3, Weekday::Fri, 2), /// NaiveDate::from_ymd_opt(2017, 3, 10)) /// ~~~~ /// /// Returns `None` if `n` out-of-range; ie. if `n` is larger than the number of `weekday` in /// `month` (eg. the 6th Friday of March 2017), or if `n == 0`. - pub fn from_ymwd_opt(year: i32, month: u32, weekday: Weekday, n: u8) -> Option { + pub fn from_weekday_of_month_opt(year: i32, month: u32, weekday: Weekday, n: u8) -> Option { if n == 0 { return None; } let first = NaiveDate::from_ymd(year, month, 1).weekday(); let first_to_dow = (7 + weekday.number_from_monday() - first.number_from_monday()) % 7; @@ -1873,8 +1873,8 @@ mod tests { } #[test] - fn test_date_from_ymwd_opt() { - let ymwd = |y,m,w,n| NaiveDate::from_ymwd_opt(y,m,w,n); + fn test_date_from_weekday_of_month_opt() { + let ymwd = |y,m,w,n| NaiveDate::from_weekday_of_month_opt(y,m,w,n); assert_eq!(ymwd(2018, 8, Weekday::Tue, 0), None); assert_eq!(ymwd(2018, 8, Weekday::Wed, 1), Some(NaiveDate::from_ymd(2018, 8, 1))); assert_eq!(ymwd(2018, 8, Weekday::Thu, 1), Some(NaiveDate::from_ymd(2018, 8, 2)));