Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

tai64: time is wrong in different ways

Đang mở
#2,012 1 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
rust
Lĩnh vực
backend

Hướng nghiên cứu

Bắt đầu với tai64/src/lib.rs tại UNIX_EPOCH, from_unix và to_unix, sau đó chạy trình tái hiện Rust được cung cấp. So sánh các phép chuyển đổi của crate với mối quan hệ đã được ghi lại giữa TAI, UTC và thời gian Unix, bao gồm cả giây nhuận. Hoàn thành khi các hằng số và phương thức chuyển đổi nhất quán biểu diễn các tiêu chuẩn thời gian dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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

Ngôn ngữ chính
Rust
Star
338
Fork
188
Merge trung bình
4 ngày 6 giờ
Pull request đã merge (30 ngày)
15

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của RustCrypto/formats

Tất cả issue của RustCrypto/formats

Issue tương tự

Thêm issue về Rust

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.