Struct dtt::DateTime

source ·
pub struct DateTime {
Show 15 fields pub day: u8, pub hour: u8, pub iso_8601: String, pub iso_week: u8, pub microsecond: u32, pub minute: u8, pub month: String, pub now: String, pub offset: String, pub ordinal: u16, pub second: u8, pub time: String, pub tz: String, pub weekday: String, pub year: i32,
}
Expand description

DateTime struct to ease dates and times manipulation.

This module includes date and time types, such as day, hour,ISO 8601 date and time, and many more methods.

Fields§

§day: u8

Day of the month: (1-31)

§hour: u8

Hour of the day: (0-23)

§iso_8601: String

ISO 8601 date and time: (e.g. “2023-01-01T00:00:00+00:00”)

§iso_week: u8

ISO week number: (1-53)

§microsecond: u32

Microsecond: (0-999999)

§minute: u8

Minute of the hour: (0-59)

§month: String

Month: (e.g. “January”)

§now: String

Now object: (e.g. “2023-01-01”)

§offset: String

Offset from UTC: (e.g. “+00:00”)

§ordinal: u16

Ordinal date: (1-366)

§second: u8

Second of the minute: (0-59)

§time: String

Time object: (e.g. “00:00:00”)

§tz: String

Tz object: (e.g. “UTC”)

§weekday: String

Weekday object: (e.g. “Monday”)

§year: i32

Year object: (e.g. “2023”)

Implementations§

source§

impl DateTime

source

pub fn new() -> DateTime

Create a new Date object with UTC timezone.

source

pub fn new_with_tz(tz: &str) -> Self

Create a new DateTime object with a custom timezone.

source

pub fn is_valid_day(input: &str) -> bool

Check if the input is a valid day. 31 is valid. 32 is not valid.

source

pub fn is_valid_hour(input: &str) -> bool

Check if the input is a valid hour. 23:59 is valid. 24:00 is not valid.

source

pub fn is_valid_minute(input: &str) -> bool

Check if the input is a valid minute. 59 is valid. 60 is not valid.

source

pub fn is_valid_month(input: &str) -> bool

Check if the input is a valid month. 12 is valid. 13 is not valid.

source

pub fn is_valid_ordinal(input: &str) -> bool

Check if the input is a valid ordinal date. 366 is valid. 367 is not valid.

source

pub fn is_valid_second(input: &str) -> bool

Check if the input is a valid second. 59 is valid. 60 is not valid.

source

pub fn is_valid_time(input: &str) -> bool

Check if the input is a valid time. 23:59:59 is valid. 24:00:00 is not valid.

source

pub fn is_valid_iso_8601(input: &str) -> bool

Check if the input is a valid ISO 8601 date and time. 2023-01-01T00:00:00+00:00 is valid. 2023-01-01T00:00:00+00:00:00 is not valid.

source

pub fn is_valid_iso_week(input: &str) -> bool

Check if the input is a valid ISO week number. 53 is valid. 54 is not valid.

source

pub fn is_valid_microsecond(input: &str) -> bool

Check if the input is a valid microsecond. 999999 is valid. 1000000 is not valid.

source

pub fn update(&mut self) -> String

Update the date and time.

source

pub fn next_day(&self) -> DateTime

Calculate the next day. Returns a new DateTime struct. The time zone is not updated.

source

pub fn relative_delta(&self) -> DateTime

Calculates the relative delta based on the current date and time and the fields of the RelativeDelta structure. Returns the DateTime structure that represents the resulting date and time.

source

pub fn previous_day(&self) -> DateTime

Calculate the previous day. Returns the DateTime structure that represents the resulting date and time.

Trait Implementations§

source§

impl Clone for DateTime

source§

fn clone(&self) -> DateTime

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 Debug for DateTime

source§

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

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

impl Default for DateTime

source§

fn default() -> DateTime

Returns the “default value” for a type. Read more
source§

impl<'de> Deserialize<'de> for DateTime

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 Display for DateTime

source§

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

Display the date and time in ISO 8601 format.

source§

impl FromStr for DateTime

§

type Err = ()

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
source§

impl PartialEq<DateTime> for DateTime

source§

fn eq(&self, other: &DateTime) -> 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 Serialize for DateTime

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 StructuralPartialEq for DateTime

Auto Trait Implementations§

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,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. 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.
const: unstable · 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.
const: unstable · 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>,