tai64: time is wrong in different ways
还没有人认领这个 Issue。
评估
调研方向
从 tai64/src/lib.rs 中的 UNIX_EPOCH、from_unix 和 to_unix 开始,然后运行所提供的 Rust 复现程序。将 crate 的转换与文档中说明的 TAI、UTC 和 Unix 时间之间的关系进行比较,包括闰秒。完成的标准是常量和转换方法能够一致地表示预期的时间标准。
由索引模型根据 Issue 内容生成。
描述
TLDR: Second assertion in the following code fails.
fn main() {
let now_tai = tai64::Tai64::now();
let now_std = std::time::SystemTime::now();
// making sure the second didn't change between measurements
assert_eq!(now_tai, tai64::Tai64::now());
let now_tai_unix: u64 = now_tai
.to_unix()
.try_into()
.expect("21st century");
let now_std_unix: u64 = now_std
.duration_since(std::time::SystemTime::UNIX_EPOCH)
.expect("21st century")
.as_secs();
assert_eq!(now_tai_unix, now_std_unix);
}
thread 'main' panicked at src/main.rs:17:5:
assertion `left == right` failed
left: 1756146344
right: 1756146317
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
Time standards are anything but trivial. TAI, UTC, and Unix time are three different time standards. In particular, they differ in how they handle leap seconds. The crate tai64 attempts to solve the conversion between TAI64 and Unix timestamps, which are (semi)standardized binary representations of a moment in time in TAI and Unix time respectively. Since Unix time is defined from UTC, which in turn defined from TAI, we should discuss relationship between the latter two.
By definition, 1 January 1972 00:00:00 UTC is 1 January 1972 00:00:10 TAI exactly[^1]. Yet, at the moment of writing, The current difference between UTC and TAI is 37 seconds. (TAI is ahead of UTC by this amount)[^2]. Change in difference over time comes from leap seconds, which have been inserted in 27 times since 1972.
[^1]: Blair 1974, p. 32.
[^2]: Leap second and UT1-UTC information. NIST.
This means that the difference between representations of a moment in time in TAI and UTC is not only a function of the current moment in time but also of the moment in question.
The problem with the current implementation isn't limited to the offset being constant: it is inconsistent. In UNIX_EPOCH it is 37, but in the methods from_unix and to_unix, it is 10:
https://github.com/RustCrypto/formats/blob/950e25e5327f7ecc9fbd7fb585d1967cbd80067c/tai64/src/lib.rs#L40
https://github.com/RustCrypto/formats/blob/950e25e5327f7ecc9fbd7fb585d1967cbd80067c/tai64/src/lib.rs#L63
https://github.com/RustCrypto/formats/blob/950e25e5327f7ecc9fbd7fb585d1967cbd80067c/tai64/src/lib.rs#L68
- 主要语言
- Rust
- 星标
- 338
- 派生
- 188
- 平均合并
- 4 天 6 小时
- 30 天内合并 PR
- 15
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RustCrypto/formats 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 86/100
RustCrypto/formats#2389 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 68/100
RustCrypto/formats#2366 ·
-
难度 5/5 一周以上 新手友好度 25/100
RustCrypto/formats#2430 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 48/100
RustCrypto/formats#2428 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
RustCrypto/formats#2427 · 1 条评论 ·
查看 RustCrypto/formats 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
TheLarkInn/aipm#2413 ·
-
documentation
难度 1/5 1 小时以内 新手友好度 90/100
alexgorbatchev/simple-ptt#15 ·
-
tooling
难度 2/5 1-3 小时 新手友好度 75/100
-
todo:ticket
难度 2/5 1-3 小时 新手友好度 70/100
-
难度 2/5 1-3 小时 新手友好度 75/100
taikoxyz/taiko-mono#22168 · 1 条评论 ·