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

High Precision TAI Timestamp #61

Open
dukesook opened this issue Jul 17, 2024 · 4 comments
Open

High Precision TAI Timestamp #61

dukesook opened this issue Jul 17, 2024 · 4 comments
Labels

Comments

@dukesook
Copy link

Hello,

Does this repository support TAI timestamps with greater precision than milliseconds? Like microseconds or even nanoseconds?

@qntm
Copy link
Owner

qntm commented Jul 17, 2024

Right now this library only accepts integer millisecond counts as input and throws an exception otherwise. It also returns results truncated to the millisecond. The reason for this is that this is how JavaScript time is expressed.

However, there is some semi-secret internal infrastructure which carries out all the relevant calculations using precise ratios of BigInts. We only truncate at the very end, everything internal is exact. It could be possible to expose this interface, or some kind of microsecond converter or nanosecond converter or similar.

What are your actual requirements? Or are you just curious?

@qntm qntm added the question label Jul 17, 2024
@dukesook
Copy link
Author

MPEG is adding a TAI nanosecond timestamp capability for their HEIF & MP4 files. I'm wondering if there's any open-source tool to convert such a timestamp to/from a human readable form. However, It seems like everyone uses UTC with millisecond precision.

I would be interested in such an interface that handles an arbitrary level of precision.

@qntm
Copy link
Owner

qntm commented Jul 17, 2024

I see. Well, some of the pieces for that are in place, but I wouldn't exactly call them suitable for public consumption, there's a decent amount of jank. Let me think about the best way to provide that interface.

@qntm
Copy link
Owner

qntm commented Sep 16, 2024

@dukesook I should probably mention that you may be able to get away with:

const OFFSET_MILLIS = 37_000
const unixToAtomic = x => x + OFFSET_MILLIS
const atomicToUnix = x => x - OFFSET_MILLIS

Similarly for microseconds, nanoseconds or whatever. This implementation is sufficient for your needs provided that

  1. you don't need to handle any dates prior to 2017, and
  2. the abolition of leap seconds, currently expected to occur in or before 2035, is completed before any more leap seconds are announced, which on current showing seems quite possible.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants