qntm / t-a-i

Converts Unix milliseconds to and from International Atomic Time (TAI) milliseconds
MIT License
43 stars 2 forks source link

V3 #17

Closed qntm closed 3 years ago

qntm commented 3 years ago

Completely overhaul the API. t-a-i now exports a constructor TaiConverter and a collection of four MODELS, one of which is passed to the constructor to specify in advance the relationship between TAI and Unix time and hence the behaviour of all conversions. The constructor then only has two methods, unixToAtomic and atomicToUnix. Special options can be passed to unixToAtomic in some cases, to retrieve full arrays or closed ranges of TAI millisecond counts in cases where the relationship is one-to-many.

In order to get the arithmetic correct for the new SMEAR model, I added a very rudimentary class Rat expressing a ratio between two BigInts, and another new class Segment which expresses a bounded segment with an origin point and slope, expressed using Rats. Segment can do precise bounds checking and conversions even in asinine situations like smearing out the removal of 0.05 TAI seconds from Unix time. Finally, I upgraded munge to factor in the choice of model before constructing the collection of Segments to pass to the converter - which is largely model-agnostic in its behaviour (well, not really).

The STALL model was a lot of fun because it involves a perfectly horizontal Segment with slope 0 and a bunch of special cases.

Fixes #15.