#date-time #freedom

freedom-dates

创建并打印 Freedom 格式的日期

1 个稳定版本

1.0.0 2023年2月8日

#423日期和时间

自定义许可证

11KB
162

Freedom Dates

没有人应该把我认为是展示书面日期的正确方式弄错了。 ——乔治·华盛顿将军

freedom-dates 库提供了一组方便的工具,用于处理 freedom 格式 的日期。也就是说,它将类似 "2023-02-08" 的共产格式日期表示形式解放为类似 "2/8/23" 的自由格式。

    let communism = "2023-02-08T12:00:00-07:00";

    let freedom = FreedomDate::liberate(communism).unwrap();
    
    assert_eq!("2/7/23", &result.to_string());

由于自由诞生于1776年7月4日(《7/4/76》),因此在此之前的日期既不有效也不可表示。如果您尝试解放这样的日期,您将获得一个 FreedomError::PreCreation 错误。尝试解放“过于”共产的日期将导致一个 FreedomError::TooCommunist 错误。

    let bad_communism = "Comrade, today is the eighth of Februrary, in the year 2023.";
    let pre_history = "1775-07-04";

    let too_communist = FreedomDate::liberate(bad_communism).unwrap_err();
    let pre_historic_nonsense = FreedomDate::liberate(pre_history).unwrap_err();

    println!("'{bad_communism}' is impossible to comprehend: `{too_communist}`\n");

    println!("'{pre_history}' is not a real date: `{pre_historic_nonsense}`\n");

将打印出来

'Comrade, today is the eighth of Februrary, in the year 2023.' is impossible to comprehend: I't speak your crazy Communism-language! 'Comrade, today is the eighth of Februrary, in the year 2023.'

'1775-07-04' is not a real date: That't hardly make no sense, '1775-07-04' is before the very start of Time/Freedom itself.

A freedomstamp 是自由诞生以来的秒数,正整数可以转换为 FreedomDates

    // `From<u64>` is implemented for FreedomDates
    let birthday_of_freedom: FreedomDate = 0.into();
    println!("The Birthday of Freedom is {birthday_of_freedom}\n");

将打印

自由的日子是 7/4/76

并且

    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()
    );

将打印

自由诞生后的第二天,7/5/76,已经过去了 86400 秒。

这些示例可以在 导游 中找到。

版本控制

自由 数字 1 开始,宝贝!每个版本都是前一个版本的十倍,所以第二个版本是 10,然后是 100,等等。自由!

许可证

本软件在 混沌许可证 下发布

依赖项

~3.5–4.5MB
~75K SLoC