3 个稳定版本

1.0.5 2024 年 8 月 5 日

#103日期和时间

Download history 311/week @ 2024-08-05

311 每月下载量

MIT 许可证

19KB
523

TTTime Rust 库

TTTime 是一种十进制时间表示法。它以易于理解和处理的方式表示时间。时间从 18:00:00 - 2020/10/21 UTC 标准时间(第 0 天)开始计量。

此实现缺少一些功能,主要是与标准时间的交互,它也存在一些小错误,如果有任何建议或想贡献,请在此处提出问题 https://github.com/tonyaellie/tttime

Day Zero: 18:00:00 - 21/10/2020 UTC
1 TTT Hour = 1 Hour Standard Time
100 TTT Seconds in a TTT Minute
100 TTT Minutes in a TTT Hour
100 TTT Hours in a TTT Day
10 TTT Days in a TTT Month
10 TTT Months in a TTT Year

优点

  • 易于理解和处理
  • 没有时区和夏令时
  • 没有闰年

安装和使用

  cargo add tttime
use tttime::{TTTime, TTTimeInput, TTTimePartial};

let mut time = TTTime::new(None);
time.set_year(2020);
time.set_month(9);
time.set_day(2);
time.set_hour(18);
time.set_minute(0);
time.set_second(0);
time.set_millisecond(0);

println!("{}", time.to_string("%Y-%m-%d %H:%M:%S"));
// 2020-09-02 18:00:00

API

impl TTTime {
    pub fn new(input: Option<TTTimeInput>) -> Self;

    pub fn get_year(&self) -> u64;
    pub fn get_month(&self) -> u64;
    pub fn get_day(&self) -> u64;
    pub fn get_hour(&self) -> u64;
    pub fn get_minute(&self) -> u64;
    pub fn get_second(&self) -> u64;
    pub fn get_millisecond(&self) -> u64;

    pub fn set_year(&mut self, year: u64);
    pub fn set_month(&mut self, month: u64);
    pub fn set_day(&mut self, day: u64);
    pub fn set_hour(&mut self, hour: u64);
    pub fn set_minute(&mut self, minute: u64);
    pub fn set_second(&mut self, second: u64);
    pub fn set_millisecond(&mut self, millisecond: u64);

    pub fn add(&mut self, time: TTTime);
    pub fn subtract(&mut self, time: TTTime);

    pub fn is_before(&self, time: TTTime) -> bool;
    pub fn is_after(&self, time: TTTime) -> bool;
    pub fn is_equal(&self, time: TTTime) -> bool;

    pub fn to_string(&self, format: &str) -> String;
}

没有运行时依赖