Struct sqldatetime::Date
source · #[repr(transparent)]pub struct Date(_);
Expand description
Date represents a valid Gregorian date.
Implementations§
source§impl Date
impl Date
sourcepub const unsafe fn from_ymd_unchecked(year: i32, month: u32, day: u32) -> Date
pub const unsafe fn from_ymd_unchecked(year: i32, month: u32, day: u32) -> Date
Creates a Date
from the given year, month, and day.
Safety
This function is unsafe because the values are not checked for validity! Before using it, check that the values are all correct.
sourcepub const fn try_from_ymd(
year: i32,
month: u32,
day: u32
) -> Result<Date, Error>
pub const fn try_from_ymd( year: i32, month: u32, day: u32 ) -> Result<Date, Error>
Creates a Date
from the given year, month, and day.
sourcepub const fn is_valid(year: i32, month: u32, day: u32) -> bool
pub const fn is_valid(year: i32, month: u32, day: u32) -> bool
Checks if the given year, month, and day fields are valid.
sourcepub const unsafe fn from_days_unchecked(days: i32) -> Self
pub const unsafe fn from_days_unchecked(days: i32) -> Self
Creates a Date
from the given days from Unix Epoch without checking validity.
Safety
This function is unsafe because the day value is not checked for validity! Before using it, check that the value is correct.
sourcepub const fn try_from_days(days: i32) -> Result<Self, Error>
pub const fn try_from_days(days: i32) -> Result<Self, Error>
Creates a Date
from the given days from Unix Epoch.
sourcepub fn and_hms(
self,
hour: u32,
minute: u32,
sec: u32,
usec: u32
) -> Result<Timestamp, Error>
pub fn and_hms( self, hour: u32, minute: u32, sec: u32, usec: u32 ) -> Result<Timestamp, Error>
Makes a new Timestamp
from the current date, hour, minute, second and microsecond.
sourcepub const fn and_time(self, time: Time) -> Timestamp
pub const fn and_time(self, time: Time) -> Timestamp
Makes a new Timestamp
from the current date and time.
sourcepub fn format<S: AsRef<str>>(self, fmt: S) -> Result<impl Display, Error>
pub fn format<S: AsRef<str>>(self, fmt: S) -> Result<impl Display, Error>
Formats Date
by given format string.
sourcepub fn parse<S1: AsRef<str>, S2: AsRef<str>>(
input: S1,
fmt: S2
) -> Result<Self, Error>
pub fn parse<S1: AsRef<str>, S2: AsRef<str>>( input: S1, fmt: S2 ) -> Result<Self, Error>
Parses Date
from given string and format.
sourcepub fn add_months(self, months: i32) -> Result<Date, Error>
pub fn add_months(self, months: i32) -> Result<Date, Error>
Date
adds months.
The date will be adjusted.
The last day of the month is not considered.
sourcepub fn add_months2(self, months: i32) -> Result<Date, Error>
pub fn add_months2(self, months: i32) -> Result<Date, Error>
Date
adds months.
The date will be adjusted.
The last day of the month is considered.
sourcepub fn add_interval_ym(self, interval: IntervalYM) -> Result<Timestamp, Error>
pub fn add_interval_ym(self, interval: IntervalYM) -> Result<Timestamp, Error>
Date
adds IntervalYM
The date will not be adjusted.
sourcepub const fn add_interval_dt(
self,
interval: IntervalDT
) -> Result<Timestamp, Error>
pub const fn add_interval_dt( self, interval: IntervalDT ) -> Result<Timestamp, Error>
Date
adds IntervalDT
sourcepub const fn sub_date(self, date: Date) -> i32
pub const fn sub_date(self, date: Date) -> i32
Date
subtracts Date
. Returns the difference in days between two Date
sourcepub const fn sub_timestamp(self, timestamp: Timestamp) -> IntervalDT
pub const fn sub_timestamp(self, timestamp: Timestamp) -> IntervalDT
Date
subtracts Timestamp
sourcepub fn sub_interval_ym(self, interval: IntervalYM) -> Result<Timestamp, Error>
pub fn sub_interval_ym(self, interval: IntervalYM) -> Result<Timestamp, Error>
Date
subtracts IntervalYM
sourcepub const fn sub_interval_dt(
self,
interval: IntervalDT
) -> Result<Timestamp, Error>
pub const fn sub_interval_dt( self, interval: IntervalDT ) -> Result<Timestamp, Error>
Date
subtracts IntervalDT
sourcepub fn day_of_week(self) -> WeekDay
pub fn day_of_week(self) -> WeekDay
Extract day of week (1..=7 Sunday..=Saturday)
sourcepub fn last_day_of_month(self) -> Date
pub fn last_day_of_month(self) -> Date
Gets the last day in month of this Date
.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Date
Available on crate feature serde
only.
impl<'de> Deserialize<'de> for Date
serde
only.source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,
source§impl Ord for Date
impl Ord for Date
source§impl PartialEq<Date> for Date
impl PartialEq<Date> for Date
source§impl PartialEq<Date> for Date
impl PartialEq<Date> for Date
source§impl PartialEq<Date> for SqlDate
impl PartialEq<Date> for SqlDate
source§impl PartialEq<Date> for Timestamp
impl PartialEq<Date> for Timestamp
source§impl PartialEq<Timestamp> for Date
impl PartialEq<Timestamp> for Date
source§impl PartialOrd<Date> for Date
impl PartialOrd<Date> for Date
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Date> for Date
impl PartialOrd<Date> for Date
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Date> for SqlDate
impl PartialOrd<Date> for SqlDate
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Date> for Timestamp
impl PartialOrd<Date> for Timestamp
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<Timestamp> for Date
impl PartialOrd<Timestamp> for Date
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read more