B4UDW3RK5 / beatTAI

New Internet time for turbonerds & superweirdos.
The Unlicense
3 stars 0 forks source link

Doesn't the Go version [sometimes] overflow :999.99? #3

Open kseistrup opened 2 days ago

kseistrup commented 2 days ago

If I have understood this correctly, then beatTAI will show number of beats (1000th of a day) relative to TAI.

However, the Go code goes from UTC to seconds with [essentially] (HH * 60 + MM) * 60 + SS, and then adds TAI offset.

So at 23:59:59 UTC we have

>>> (23 * 60 + 59) * 60 + 59 + 37
86436
>>> round(86436 / 86.4, 2)
1000.42

But the last centibeat in the current day should be :999.99.

So the number of (seconds + offset) should be modulus 86400 before dividing with 86.4.


edit: typo

kseistrup commented 2 days ago

PS: On Linux, it should be possible to do something like this in Python:

#!/usr/bin/env python

from time import (clock_gettime, CLOCK_TAI)

SECS_PER_DAY = 24 * 60 * 60
secs = clock_gettime(CLOCK_TAI) % SECS_PER_DAY
beats = round(secs * 1000 / SECS_PER_DAY, 2)

print(f':{beats:06.2f}')

# eof

E.g.:

» python beattai.py
:775.84