pub struct Date {
pub year: u16,
pub month: u8,
pub day: u8,
}Expand description
A simple date in the Gregorian calendar without time zone information.
Fields§
§year: u16The year as commonly used in a date.
The range of 2000 to 2099 is guaranteed to be supported by all methods. For support beyond this range, consult the documentation of the respective implementation.
month: u8Month of the year [1-12].
day: u8Day of the month [1-31].
Implementations§
Source§impl Date
impl Date
Sourcepub fn new(year: u16, month: u8, day: u8) -> Self
pub fn new(year: u16, month: u8, day: u8) -> Self
Create a new Date from year, month and day.
No checks will be performed to validate the date.
Sourcepub fn new_checked(year: u16, month: u8, day: u8) -> Option<Self>
pub fn new_checked(year: u16, month: u8, day: u8) -> Option<Self>
Create a new Date from year, month and day.
Returns None if the year, month or day is invalid.
The year must be between 2000 and 2199. This range might be extended in the future if the implementation supports it.
Sourcepub fn is_valid(self) -> bool
pub fn is_valid(self) -> bool
Determine whether the date is a valid combination of year, month and day.
This is guaranteed to work for the years between 2000 and 2199, inclusive.
Years outside of this range will return arbitrary results or may panic.
Sourcepub fn is_leap_year(self) -> bool
pub fn is_leap_year(self) -> bool
Helper function to determine whether a given year is a leap year.
This is guaranteed to work for the years between 2000 and 2199.
Years outside of this range will return arbitrary results or may panic.
Sourcepub fn with_time(self, time: Time) -> DateTime
pub fn with_time(self, time: Time) -> DateTime
Create a new DateTime from a Date and a Time.
Returns None if the hours, minutes or seconds is invalid.
Sourcepub fn year2000(self) -> u8
pub fn year2000(self) -> u8
Returns the year relative to 2000.
This is guaranteed to work for the years between 2000 and 2255, inclusive.
The purpose of this method is to obtain a year with reduced width for cheaper calculations. Subtracting 2000 preserves the leap year pattern.
Years outside of this range will return arbitrary results or may panic.