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

Re-exported main DateTime type from dtt for date/time handling.

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 parse(input: &str) -> Result<DateTime, &'static str>

Parse the input string and create a new DateTime object.

This function takes an input string and attempts to parse it into a DateTime object. The input string can be in ISO 8601 format or a date-only format (YYYY-MM-DD). If the input matches the ISO 8601 format, the resulting DateTime object will be set to the current UTC time. If the input matches the date-only format, the resulting DateTime object will have the time components set to zero and the timezone set to UTC.

Arguments
  • input - A string slice that represents the date and time to parse.
Returns
  • Result<DateTime, &'static str> - A result indicating either the successfully parsed DateTime object or an error message if the input format is invalid.
source

pub fn new() -> DateTime

Create a new Date object with UTC timezone.

source

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

Create a new DateTime object with a custom timezone. Custom timezones supported by DateTime (DTT) are:

AbbreviationUtcOffsetTime Zone Description
ACDTUtcOffset::from_hms(10, 30, 0)Australian Central Daylight Time
ACSTUtcOffset::from_hms(9, 30, 0)Australian Central Standard Time
ADTUtcOffset::from_hms(-3, 0, 0)Atlantic Daylight Time
AEDTUtcOffset::from_hms(11, 0, 0)Australian Eastern Daylight Time
AESTUtcOffset::from_hms(10, 0, 0)Australian Eastern Standard Time
AKDTUtcOffset::from_hms(-8, 0, 0)Alaska Daylight Time
AKSTUtcOffset::from_hms(-9, 0, 0)Alaska Standard Time
ASTUtcOffset::from_hms(-4, 0, 0)Atlantic Standard Time
AWSTUtcOffset::from_hms(8, 0, 0)Australian Western Standard Time
BSTUtcOffset::from_hms(1, 0, 0)British Summer Time
CDTUtcOffset::from_hms(-5, 0, 0)Central Daylight Time
CESTUtcOffset::from_hms(2, 0, 0)Central European Summer Time
CETUtcOffset::from_hms(1, 0, 0)Central European Time
CSTUtcOffset::from_hms(-6, 0, 0)Central Standard Time
ECTUtcOffset::from_hms(-4, 0, 0)Eastern Caribbean Time
EDTUtcOffset::from_hms(-4, 0, 0)Eastern Daylight Time
EESTUtcOffset::from_hms(3, 0, 0)Eastern European Summer Time
EETUtcOffset::from_hms(2, 0, 0)Eastern European Time
ESTUtcOffset::from_hms(-5, 0, 0)Eastern Standard Time
GMTUtcOffset::from_hms(0, 0, 0)Greenwich Mean Time
HADTUtcOffset::from_hms(-9, 0, 0)Hawaii-Aleutian Daylight Time
HASTUtcOffset::from_hms(-10, 0, 0)Hawaii-Aleutian Standard Time
HKTUtcOffset::from_hms(8, 0, 0)Hong Kong Time
ISTUtcOffset::from_hms(5, 30, 0)Indian Standard Time
IDTUtcOffset::from_hms(3, 0, 0)Israel Daylight Time
JSTUtcOffset::from_hms(9, 0, 0)Japan Standard Time
KSTUtcOffset::from_hms(9, 0, 0)Korean Standard Time
MDTUtcOffset::from_hms(-6, 0, 0)Mountain Daylight Time
MSTUtcOffset::from_hms(-7, 0, 0)Mountain Standard Time
NZDTUtcOffset::from_hms(13, 0, 0)New Zealand Daylight Time
NZSTUtcOffset::from_hms(12, 0, 0)New Zealand Standard Time
PDTUtcOffset::from_hms(-7, 0, 0)Pacific Daylight Time
PSTUtcOffset::from_hms(-8, 0, 0)Pacific Standard Time
UTCUtcOffset::from_hms(0, 0, 0)Coordinated Universal Time
WADTUtcOffset::from_hms(8, 45, 0)West Australian Daylight Time
WASTUtcOffset::from_hms(7, 0, 0)West Australian Standard Time
WEDTUtcOffset::from_hms(1, 0, 0)Western European Daylight Time
WESTUtcOffset::from_hms(1, 0, 0)Western European Summer Time
WETUtcOffset::from_hms(0, 0, 0)Western European Time
WSTUtcOffset::from_hms(8, 0, 0)Western Standard Time
Example
use dtt::DateTime;
use dtt::dtt_print;

let paris_time = DateTime::new_with_tz("CEST");
dtt_print!(paris_time);
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<(), Error>

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<DateTime, <__D as Deserializer<'de>>::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<(), Error>

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<DateTime, <DateTime as FromStr>::Err>

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

impl PartialEq 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 as Serializer>::Ok, <__S as Serializer>::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 T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where 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.

§

impl<T> FromBase64 for T
where T: for<'de> Deserialize<'de>,

§

fn from_base64<Input>(raw: &Input) -> Result<T, Error>
where Input: AsRef<[u8]> + ?Sized,

source§

impl<T, U> Into<U> for T
where 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.

§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<R, P> ReadPrimitive<R> for P
where R: Read + ReadEndian<P>, P: Default,

source§

fn read_from_little_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_little_endian().
source§

fn read_from_big_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_big_endian().
source§

fn read_from_native_endian(read: &mut R) -> Result<Self, Error>

Read this value from the supplied reader. Same as ReadEndian::read_from_native_endian().
source§

impl<T> Same for T

§

type Output = T

Should always be Self
§

impl<C> SignWithKey<String> for C
where C: ToBase64,

§

fn sign_with_key(self, key: &impl SigningAlgorithm) -> Result<String, Error>

§

impl<T> ToBase64 for T
where T: Serialize,

§

fn to_base64(&self) -> Result<Cow<'_, str>, Error>

source§

impl<T> ToOwned for T
where 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 T
where 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 T
where 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 T
where 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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

source§

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