Struct sqldatetime::Date

source ·
#[repr(transparent)]
pub struct Date(_);
Expand description

Date represents a valid Gregorian date.

Implementations§

source§

impl Date

source

pub const MIN: Self = _

The smallest date that can be represented by Date, i.e. 0001-01-01.

source

pub const MAX: Self = _

The largest date that can be represented by Date, i.e. 9999-12-31.

source

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.

source

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.

source

pub const fn is_valid(year: i32, month: u32, day: u32) -> bool

Checks if the given year, month, and day fields are valid.

source

pub const fn days(self) -> i32

Gets the days from Unix Epoch of this Date.

source

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.

source

pub const fn try_from_days(days: i32) -> Result<Self, Error>

Creates a Date from the given days from Unix Epoch.

source

pub const fn extract(self) -> (i32, u32, u32)

Extracts (year, month, day) from the date.

source

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.

source

pub const fn and_time(self, time: Time) -> Timestamp

Makes a new Timestamp from the current date and time.

source

pub fn format<S: AsRef<str>>(self, fmt: S) -> Result<impl Display, Error>

Formats Date by given format string.

source

pub fn parse<S1: AsRef<str>, S2: AsRef<str>>( input: S1, fmt: S2 ) -> Result<Self, Error>

Parses Date from given string and format.

source

pub const fn add_days(self, days: i32) -> Result<Date, Error>

Date adds days.

source

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.

source

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.

source

pub fn add_interval_ym(self, interval: IntervalYM) -> Result<Timestamp, Error>

Date adds IntervalYM The date will not be adjusted.

source

pub const fn add_interval_dt( self, interval: IntervalDT ) -> Result<Timestamp, Error>

Date adds IntervalDT

source

pub const fn add_time(self, time: Time) -> Timestamp

Date adds Time

source

pub const fn sub_date(self, date: Date) -> i32

Date subtracts Date. Returns the difference in days between two Date

source

pub const fn sub_days(self, days: i32) -> Result<Date, Error>

Date subtracts days.

source

pub const fn sub_timestamp(self, timestamp: Timestamp) -> IntervalDT

Date subtracts Timestamp

source

pub fn sub_interval_ym(self, interval: IntervalYM) -> Result<Timestamp, Error>

Date subtracts IntervalYM

source

pub const fn sub_interval_dt( self, interval: IntervalDT ) -> Result<Timestamp, Error>

Date subtracts IntervalDT

source

pub const fn sub_time(self, time: Time) -> Result<Timestamp, Error>

Date subtracts Time

source

pub fn day_of_week(self) -> WeekDay

Extract day of week (1..=7 Sunday..=Saturday)

source

pub fn now() -> Result<Date, Error>

Get local system date

source

pub fn last_day_of_month(self) -> Date

Gets the last day in month of this Date.

Trait Implementations§

source§

impl Clone for Date

source§

fn clone(&self) -> Date

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl DateTime for Date

source§

fn year(&self) -> Option<i32>

Extracts year from date time.
source§

fn month(&self) -> Option<i32>

Extracts month from date time.
source§

fn day(&self) -> Option<i32>

Extracts day from date time.
source§

fn hour(&self) -> Option<i32>

Extracts hour from date time.
source§

fn minute(&self) -> Option<i32>

Extracts minute from date time.
source§

fn second(&self) -> Option<f64>

Extracts second from date time.
source§

fn date(&self) -> Option<Date>

Extracts second from date time.
source§

impl Debug for Date

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Date

Available on crate feature serde only.
source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl From<Date> for Timestamp

source§

fn from(date: Date) -> Self

Converts to this type from the input type.
source§

impl Hash for Date

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl Ord for Date

source§

fn cmp(&self, other: &Date) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Date> for Date

source§

fn eq(&self, other: &Date) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Date> for Date

source§

fn eq(&self, other: &SqlDate) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Date> for SqlDate

source§

fn eq(&self, other: &Date) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Date> for Timestamp

source§

fn eq(&self, other: &Date) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialEq<Timestamp> for Date

source§

fn eq(&self, other: &Timestamp) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Date> for Date

source§

fn partial_cmp(&self, other: &Date) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Date> for Date

source§

fn partial_cmp(&self, other: &SqlDate) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Date> for SqlDate

source§

fn partial_cmp(&self, other: &Date) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Date> for Timestamp

source§

fn partial_cmp(&self, other: &Date) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl PartialOrd<Timestamp> for Date

source§

fn partial_cmp(&self, other: &Timestamp) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Round for Date

source§

fn round_century(self) -> Result<Self, Error>

If year is more than half of century, rounds to the first day of next century, else truncates. Read more
source§

fn round_year(self) -> Result<Self, Error>

If month is bigger than June, rounds to the first day of next year, else truncates. Read more
source§

fn round_iso_year(self) -> Result<Self, Error>

If month is bigger than June, rounds to the first day of week in next year, else truncates. Read more
source§

fn round_quarter(self) -> Result<Self, Error>

Rounds up on the sixteenth day of the second month of the quarter, else truncates. Read more
source§

fn round_month(self) -> Result<Self, Error>

Rounds up on the sixteenth day of each month, else truncates. Read more
source§

fn round_week(self) -> Result<Self, Error>

Rounds up on the fifth day of each week, the same day of the week as the first day of the year, else truncates. Read more
source§

fn round_iso_week(self) -> Result<Self, Error>

Rounds up on the fifth day of each week, Monday be the first day of week, else truncates. Read more
source§

fn round_month_start_week(self) -> Result<Self, Error>

Rounds up on the fifth day of each week, the same day of the week as the first day of the month, else truncates. Read more
source§

fn round_day(self) -> Result<Self, Error>

Rounds up at 12:00 of each day, else truncates. Read more
source§

fn round_sunday_start_week(self) -> Result<Self, Error>

Rounds up on the fifth day of each week, Sunday be the first day of week, else truncates. Read more
source§

fn round_hour(self) -> Result<Self, Error>

Rounds up at half of each hour, else truncates. Read more
source§

fn round_minute(self) -> Result<Self, Error>

Rounds up at half of each minute, else truncates. Read more
source§

impl Serialize for Date

Available on crate feature serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Trunc for Date

source§

fn trunc_century(self) -> Result<Self, Error>

Truncates to the first day of the century. Read more
source§

fn trunc_year(self) -> Result<Self, Error>

Truncates to the first day of the year. Read more
source§

fn trunc_iso_year(self) -> Result<Self, Error>

Truncates to the first day of the first week in the year. Read more
source§

fn trunc_quarter(self) -> Result<Self, Error>

Truncates to the first day of the quarter. Read more
source§

fn trunc_month(self) -> Result<Self, Error>

Truncates to the first day of the month. Read more
source§

fn trunc_week(self) -> Result<Self, Error>

Truncates to the same day of the week as the first day of the year. Read more
source§

fn trunc_iso_week(self) -> Result<Self, Error>

Truncates to the monday of the week. Read more
source§

fn trunc_month_start_week(self) -> Result<Self, Error>

Truncates to the same day of the week as the first day of the month. Read more
source§

fn trunc_day(self) -> Result<Self, Error>

Truncates to the day. Read more
source§

fn trunc_sunday_start_week(self) -> Result<Self, Error>

Truncates to the sunday of the week. Read more
source§

fn trunc_hour(self) -> Result<Self, Error>

Truncates to the hour. Read more
source§

fn trunc_minute(self) -> Result<Self, Error>

Truncates to the minute. Read more
source§

impl Copy for Date

source§

impl Eq for Date

source§

impl StructuralEq for Date

source§

impl StructuralPartialEq for Date

Auto Trait Implementations§

§

impl RefUnwindSafe for Date

§

impl Send for Date

§

impl Sync for Date

§

impl Unpin for Date

§

impl UnwindSafe for Date

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,