Struct dates_str::DateStr

source ·
pub struct DateStr<T>where
    T: ToString,
{ pub year: u64, pub month: u8, pub day: u8, /* private fields */ }
Expand description

The date struct Called DateStr because it comes from a String

Fields§

§year: u64

An unsigned 64-bit integer to hold the year

§month: u8

An unsigned 8-bit integer to hold the month Does not check if it’s in 1..12 or 0..11 range (yet)

§day: u8

An unsigned 8-bit integer to hold the day Does not check if it’s in 1..31 or 0..30 range (yet)

Implementations§

Parse a string to a DateStr struct Must be ISO format –> YYYY-MM-DD (2022-10-20)

Format the date with a custom formatter. Will be optimised. Receives a String format, and a optional separator.

let a_date: DateStr = DateStr::from_iso_str("2022-12-29");
println!("{}", a_date.format("dd-mm-yyyy", Some("/")));

Above code will output 29/12/2022

Throws an error if a formatting field is not any of the following: ["yyyy", "mm", "dd"] As said, there are no fancy features.

Trait Implementations§

Display trait implementation for DateStr Prints the date in ISO format (YYYY-MM-DD)

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.