Merge pull request #349 from gThorondorsen/fix/347

Improve documentation of `num_days_from_ce` methods
This commit is contained in:
Brandon W Maister 2019-11-16 15:17:01 -05:00 committed by GitHub
commit 8e6bc299f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 12 deletions

View File

@ -890,17 +890,18 @@ pub trait Datelike: Sized {
/// Returns `None` when the resulting value would be invalid. /// Returns `None` when the resulting value would be invalid.
fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>; fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
/// Returns the number of days since January 1, Year 1 (aka Day 1) in the /// Counts the days in the proleptic Gregorian calendar, with January 1, Year 1 (CE) as day 1.
/// proleptic Gregorian calendar.
/// ///
/// # Example: /// # Examples
/// ///
/// ~~~ /// ```
/// use chrono::{NaiveDate, Datelike}; /// use chrono::{NaiveDate, Datelike};
/// ///
/// assert_eq!(NaiveDate::from_ymd(1970, 1, 1).num_days_from_ce(), 719163); /// assert_eq!(NaiveDate::from_ymd(1970, 1, 1).num_days_from_ce(), 719_163);
/// assert_eq!(NaiveDate::from_ymd(2, 1, 1).num_days_from_ce(), 366);
/// assert_eq!(NaiveDate::from_ymd(1, 1, 1).num_days_from_ce(), 1);
/// assert_eq!(NaiveDate::from_ymd(0, 1, 1).num_days_from_ce(), -365); /// assert_eq!(NaiveDate::from_ymd(0, 1, 1).num_days_from_ce(), -365);
/// ~~~ /// ```
fn num_days_from_ce(&self) -> i32 { fn num_days_from_ce(&self) -> i32 {
// we know this wouldn't overflow since year is limited to 1/2^13 of i32's full range. // we know this wouldn't overflow since year is limited to 1/2^13 of i32's full range.
let mut year = self.year() - 1; let mut year = self.year() - 1;

View File

@ -330,10 +330,10 @@ impl NaiveDate {
} }
} }
/// Makes a new `NaiveDate` from the number of days since January 1, 1 (Day 1) /// Makes a new `NaiveDate` from a day's number in the proleptic Gregorian calendar, with
/// in the proleptic Gregorian calendar. /// January 1, 1 being day 1.
/// ///
/// Panics on the out-of-range date. /// Panics if the date is out of range.
/// ///
/// # Example /// # Example
/// ///
@ -378,10 +378,10 @@ impl NaiveDate {
NaiveDate::from_num_days_from_ce_opt(days).expect("out-of-range date") NaiveDate::from_num_days_from_ce_opt(days).expect("out-of-range date")
} }
/// Makes a new `NaiveDate` from the number of days since January 1, 1 (Day 1) /// Makes a new `NaiveDate` from a day's number in the proleptic Gregorian calendar, with
/// in the proleptic Gregorian calendar. /// January 1, 1 being day 1.
/// ///
/// Returns `None` on the out-of-range date. /// Returns `None` if the date is out of range.
/// ///
/// # Example /// # Example
/// ///