Skip to content

Commit 1784555

Browse files
committed
Change epoch of TimeUnixTAI to 1970-01-01T00:00:00.0 TAI, fixes astropy#11245
* TimeUnixTAI (name unix_tai) used the epoch ``1970-01-01T00:00:00 UTC`` since its introduction in astropy 4.2, however, contrary to the documented behaviour, this is not the definition of CLOCK_TAI on linux and no system using this epoch is known. * This switches the epoch to ``1970-01-01T00:00:00.0 TAI`` to match the intended defintion of being compatible to CLOCK_TAI on linux and also is the definition of the now obselete and already removed ``TimeUnixPTP``
1 parent fad2853 commit 1784555

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

‎CHANGES.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,12 @@ astropy.tests
381381
astropy.time
382382
^^^^^^^^^^^^
383383

384+
- Change epoch of ``TimeUnixTAI`` (``"unix_tai"``) from ``1970-01-01T00:00:00 UTC``
385+
to ``1970-01-01T00:00:00 TAI`` to match the intended and documented behaviour.
386+
This essentially changes the resulting times by 8.000082 seconds, the initial
387+
offset between TAI and UTC. [#11249]
388+
389+
384390
astropy.timeseries
385391
^^^^^^^^^^^^^^^^^^
386392

@@ -410,6 +416,11 @@ Other Changes and Additions
410416
---------------------------
411417

412418

419+
- Change epoch of ``TimeUnixTAI`` (``"unix_tai"``) from ``1970-01-01T00:00:00 UTC``
420+
to ``1970-01-01T00:00:00 TAI`` to match the intended and documented behaviour.
421+
This essentially changes the resulting times by 8.000082 seconds, the initial
422+
offset between TAI and UTC. [#11249]
423+
413424

414425
4.2 (2020-11-24)
415426
================

‎astropy/time/formats.py‎

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ def _default_scale(self):
690690

691691
class TimeUnix(TimeFromEpoch):
692692
"""
693-
Unix time: seconds from 1970-01-01 00:00:00 UTC, ignoring leap seconds.
693+
Unix time (UTC): seconds from 1970-01-01 00:00:00 UTC, ignoring to leap seconds.
694694
695695
For example, 946684800.0 in Unix time is midnight on January 1, 2000.
696696
@@ -710,38 +710,45 @@ class TimeUnix(TimeFromEpoch):
710710

711711
class TimeUnixTai(TimeUnix):
712712
"""
713-
Seconds from 1970-01-01 00:00:08 TAI (see notes), including leap seconds.
713+
Unix time (TAI): SI seconds elapsed since 1970-01-01 00:00:00 TAI (see caveats).
714714
715-
This will generally differ from Unix time by the cumulative integral number
716-
of leap seconds since 1970-01-01 UTC. This convention matches the definition
717-
for linux CLOCK_TAI (https://www.cl.cam.ac.uk/~mgk25/posix-clocks.html).
715+
This will generally differ from standard (UTC) Unix time by the cumulative
716+
integral number of leap seconds introduced into UTC since 1970-01-01 UTC.
717+
718+
This convention matches the definition of linux CLOCK_TAI
719+
(https://www.cl.cam.ac.uk/~mgk25/posix-clocks.html),
720+
and the Precision Time Protocol
721+
(https://en.wikipedia.org/wiki/Precision_Time_Protocol), which
722+
is also used by the White Rabbit protocol in High Energy Physics:
723+
https://white-rabbit.web.cern.ch.
718724
719725
Caveats:
720726
721727
- Before 1972, fractional adjustments to UTC were made, so the difference
722728
between ``unix`` and ``unix_tai`` time is no longer an integer.
723729
- Because of the fractional adjustments, to be very precise, ``unix_tai``
724-
is the number of seconds since ``1970-01-01 00:00:08 TAI`` or equivalently
725-
``1969-12-31 23:59:59.999918 UTC``. The difference between TAI and UTC
730+
is the number of seconds since ``1970-01-01 00:00:00 TAI`` or equivalently
731+
``1969-12-31 23:59:51.999918 UTC``. The difference between TAI and UTC
726732
at that epoch was 8.000082 sec.
727-
- On the day of a leap second the difference between ``unix`` and ``unix_tai``
728-
times increases linearly through the day by 1.0. See also the
733+
- On the day of a positive leap second the difference between ``unix`` and
734+
``unix_tai`` times increases linearly through the day by 1.0. See also the
729735
documentation for the `~astropy.time.TimeUnix` class.
736+
- Negative leap seconds are possible, though none have been needed to date.
730737
731738
Examples
732739
--------
733740
734741
>>> from astropy.time import Time
735742
>>> t = Time('2020-01-01', scale='utc')
736743
>>> t.unix_tai - t.unix
737-
29.0
744+
37.0
738745
739746
>>> t = Time('1970-01-01', scale='utc')
740747
>>> t.unix_tai - t.unix # doctest: +FLOAT_CMP
741-
8.200000198854696e-05
748+
8.000082
742749
"""
743750
name = 'unix_tai'
744-
epoch_val = '1970-01-01 00:00:08'
751+
epoch_val = '1970-01-01 00:00:00'
745752
epoch_scale = 'tai'
746753

747754

‎astropy/time/tests/test_basic.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1448,9 +1448,9 @@ def test_set_format_basic():
14481448

14491449
def test_unix_tai_format():
14501450
t = Time('2020-01-01', scale='utc')
1451-
assert allclose_sec(t.unix_tai - t.unix, 29.0)
1451+
assert allclose_sec(t.unix_tai - t.unix, 37.0)
14521452
t = Time('1970-01-01', scale='utc')
1453-
assert allclose_sec(t.unix_tai - t.unix, 8.2e-05)
1453+
assert allclose_sec(t.unix_tai - t.unix, 8 + 8.2e-05)
14541454

14551455

14561456
def test_set_format_shares_subfmt():

0 commit comments

Comments
 (0)