pub trait Datelike: Sized {
Show 18 methods
// Required methods
fn year(&self) -> i32;
fn month(&self) -> u32;
fn month0(&self) -> u32;
fn day(&self) -> u32;
fn day0(&self) -> u32;
fn ordinal(&self) -> u32;
fn ordinal0(&self) -> u32;
fn weekday(&self) -> Weekday;
fn iso_week(&self) -> IsoWeek;
fn with_year(&self, year: i32) -> Option<Self>;
fn with_month(&self, month: u32) -> Option<Self>;
fn with_month0(&self, month0: u32) -> Option<Self>;
fn with_day(&self, day: u32) -> Option<Self>;
fn with_day0(&self, day0: u32) -> Option<Self>;
fn with_ordinal(&self, ordinal: u32) -> Option<Self>;
fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>;
// Provided methods
fn year_ce(&self) -> (bool, u32) { ... }
fn num_days_from_ce(&self) -> i32 { ... }
}
Expand description
Trait for Timestamp
, re-exported from chrono
.
The common set of methods for date component.
Required Methods§
Sourcefn year(&self) -> i32
fn year(&self) -> i32
Returns the year number in the calendar date.
Sourcefn month(&self) -> u32
fn month(&self) -> u32
Returns the month number starting from 1.
The return value ranges from 1 to 12.
Sourcefn month0(&self) -> u32
fn month0(&self) -> u32
Returns the month number starting from 0.
The return value ranges from 0 to 11.
Sourcefn day(&self) -> u32
fn day(&self) -> u32
Returns the day of month starting from 1.
The return value ranges from 1 to 31. (The last day of month differs by months.)
Sourcefn day0(&self) -> u32
fn day0(&self) -> u32
Returns the day of month starting from 0.
The return value ranges from 0 to 30. (The last day of month differs by months.)
Sourcefn ordinal(&self) -> u32
fn ordinal(&self) -> u32
Returns the day of year starting from 1.
The return value ranges from 1 to 366. (The last day of year differs by years.)
Sourcefn ordinal0(&self) -> u32
fn ordinal0(&self) -> u32
Returns the day of year starting from 0.
The return value ranges from 0 to 365. (The last day of year differs by years.)
Sourcefn with_year(&self, year: i32) -> Option<Self>
fn with_year(&self, year: i32) -> Option<Self>
Makes a new value with the year number changed.
Returns None
when the resulting value would be invalid.
Sourcefn with_month(&self, month: u32) -> Option<Self>
fn with_month(&self, month: u32) -> Option<Self>
Makes a new value with the month number (starting from 1) changed.
Returns None
when the resulting value would be invalid.
Sourcefn with_month0(&self, month0: u32) -> Option<Self>
fn with_month0(&self, month0: u32) -> Option<Self>
Makes a new value with the month number (starting from 0) changed.
Returns None
when the resulting value would be invalid.
Sourcefn with_day(&self, day: u32) -> Option<Self>
fn with_day(&self, day: u32) -> Option<Self>
Makes a new value with the day of month (starting from 1) changed.
Returns None
when the resulting value would be invalid.
Sourcefn with_day0(&self, day0: u32) -> Option<Self>
fn with_day0(&self, day0: u32) -> Option<Self>
Makes a new value with the day of month (starting from 0) changed.
Returns None
when the resulting value would be invalid.
Sourcefn with_ordinal(&self, ordinal: u32) -> Option<Self>
fn with_ordinal(&self, ordinal: u32) -> Option<Self>
Makes a new value with the day of year (starting from 1) changed.
Returns None
when the resulting value would be invalid.
Sourcefn with_ordinal0(&self, ordinal0: u32) -> Option<Self>
fn with_ordinal0(&self, ordinal0: u32) -> Option<Self>
Makes a new value with the day of year (starting from 0) changed.
Returns None
when the resulting value would be invalid.
Provided Methods§
Sourcefn year_ce(&self) -> (bool, u32)
fn year_ce(&self) -> (bool, u32)
Returns the absolute year number starting from 1 with a boolean flag, which is false when the year predates the epoch (BCE/BC) and true otherwise (CE/AD).
Sourcefn num_days_from_ce(&self) -> i32
fn num_days_from_ce(&self) -> i32
Counts the days in the proleptic Gregorian calendar, with January 1, Year 1 (CE) as day 1.
§Examples
use chrono::{NaiveDate, Datelike};
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);
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.