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§
source§impl<T> DateStr<T>where
T: ToString,
impl<T> DateStr<T>where
T: ToString,
sourcepub fn from_iso_str(string: T) -> DateStr<T>
pub fn from_iso_str(string: T) -> DateStr<T>
Parse a string to a DateStr struct Must be ISO format –> YYYY-MM-DD (2022-10-20)
source§impl<T> DateStr<T>where
T: ToString,
impl<T> DateStr<T>where
T: ToString,
sourcepub fn format(&self, fmt: T, sep: Option<&str>) -> Result<String, FormatDateError>
pub fn format(&self, fmt: T, sep: Option<&str>) -> Result<String, FormatDateError>
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.