Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new action to update leap seconds automatically #1583

Merged
merged 2 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions .github/workflows/tai64_update_leap_seconds.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Update Leap Seconds
on:
schedule:
- cron: 0 0 * * 1

jobs:
update:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Update leap seconds in code
run: |
curl -o leap_seconds_list -L https://data.iana.org/time-zones/data/leap-seconds.list
number=$(grep -v '^#' leap_seconds_list | tail -n1 | awk '{print $2}')
sed -i "s/\(1970-01-01 00:00:\)[0-9]\+ TAI/\1${number} TAI/" tai64/src/lib.rs
sed -i -E 's/(Self\()[0-9]+ \+ \(1 << 62\)\)/\1'"${number}"' + (1 << 62))/' tai64/src/lib.rs
rm leap_seconds_list
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
commit-message: update leap seconds in tai64
title: Update leap seconds in tai64
body: 'Following this source: https://data.iana.org/time-zones/data/leap-seconds.list, the leap seconds counter has been updated.'
branch: update-leap-seconds
base: master
delete-branch: true
6 changes: 3 additions & 3 deletions tai64/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ const NANOS_PER_SECOND: u32 = 1_000_000_000;
pub struct Tai64(pub u64);

impl Tai64 {
/// Unix epoch in `TAI64`: 1970-01-01 00:00:10 TAI.
pub const UNIX_EPOCH: Self = Self(10 + (1 << 62));
/// Unix epoch in `TAI64`: 1970-01-01 00:00:37 TAI.
pub const UNIX_EPOCH: Self = Self(37 + (1 << 62));

/// Length of serialized `TAI64` timestamp in bytes.
pub const BYTE_SIZE: usize = 8;
Expand Down Expand Up @@ -151,7 +151,7 @@ impl Zeroize for Tai64N {
}

impl Tai64N {
/// Unix epoch in `TAI64N`: 1970-01-01 00:00:10 TAI.
/// Unix epoch in `TAI64N`: 1970-01-01 00:00:37 TAI.
pub const UNIX_EPOCH: Self = Self(Tai64::UNIX_EPOCH, 0);

/// Length of serialized `TAI64N` timestamp.
Expand Down