Struct freedom_dates::FreedomDate
source · pub struct FreedomDate { /* private fields */ }
Expand description
A FreedomDate is the One True Date representation. All other models are Communist.
Implementations§
source§impl FreedomDate
impl FreedomDate
sourcepub fn liberate(datestring: &str) -> Freesult
pub fn liberate(datestring: &str) -> Freesult
To liberate a representation of a date is to make it Free. But the FreeDate tree must occasionally be watered with the blood of badly-formed datestrings, and here is where the true test of Datriots is found.
Examples found in repository?
examples/tour.rs (line 8)
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
fn main() {
let good_communism = "2023-02-08T12:00:00-07:00";
let bad_communism = "Comrade, today is the eighth of Februrary, in the year 2023.";
let pre_history = "1775-07-04";
let liberated = FreedomDate::liberate(good_communism).unwrap();
let too_communist = FreedomDate::liberate(bad_communism).unwrap_err();
let pre_historic_nonsense = FreedomDate::liberate(pre_history).unwrap_err();
println!("'{good_communism}' is liberated: `{liberated}`\n");
println!("'{bad_communism}' is impossible to comprehend: `{too_communist}`\n");
println!("'{pre_history}' is not a real date: `{pre_historic_nonsense}`\n");
// `From<u64>` is implemented for FreedomDates
let birthday_of_freedom: FreedomDate = 0.into();
println!("The Birthday of Freedom is {birthday_of_freedom}\n");
// FreedomDates implement the FreedomTime trait
let one_day = Duration::days(1);
let day_after_freedom = birthday_of_freedom + one_day;
println!(
"The day after Freedom was born, {day_after_freedom}, {} seconds had passed.",
day_after_freedom.freedomstamp()
);
}
Trait Implementations§
source§impl Add<Duration> for FreedomDate
impl Add<Duration> for FreedomDate
source§impl Clone for FreedomDate
impl Clone for FreedomDate
source§fn clone(&self) -> FreedomDate
fn clone(&self) -> FreedomDate
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Debug for FreedomDate
impl Debug for FreedomDate
source§impl Default for FreedomDate
impl Default for FreedomDate
By default, FreedomDates are July 4th, ’76.
source§impl Display for FreedomDate
impl Display for FreedomDate
source§impl FreedomTime for FreedomDate
impl FreedomTime for FreedomDate
source§fn freedomstamp(&self) -> u64
fn freedomstamp(&self) -> u64
Number of whole seconds since the Birthday of Freedom.
source§impl From<u64> for FreedomDate
impl From<u64> for FreedomDate
A FreedomDate that is value
seconds after the Birthday of Freedom.
source§impl Ord for FreedomDate
impl Ord for FreedomDate
source§fn cmp(&self, other: &FreedomDate) -> Ordering
fn cmp(&self, other: &FreedomDate) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
source§impl PartialEq<FreedomDate> for FreedomDate
impl PartialEq<FreedomDate> for FreedomDate
source§fn eq(&self, other: &FreedomDate) -> bool
fn eq(&self, other: &FreedomDate) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd<FreedomDate> for FreedomDate
impl PartialOrd<FreedomDate> for FreedomDate
source§fn partial_cmp(&self, other: &FreedomDate) -> Option<Ordering>
fn partial_cmp(&self, other: &FreedomDate) -> Option<Ordering>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
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