Skip to content

Commit e739f42

Browse files
taldcrofteteq
authored andcommitted
Merge pull request #11249 from maxnoe/fix_unix_tai
Change epoch of TimeUnixTAI to 1970-01-01T00:00:00.0 TAI, fixes #11245
1 parent a30ff72 commit e739f42

3 files changed

Lines changed: 40 additions & 14 deletions

File tree

‎CHANGES.rst‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,12 @@ astropy.tests
350350
astropy.time
351351
^^^^^^^^^^^^
352352

353+
- Change epoch of ``TimeUnixTAI`` (``"unix_tai"``) from ``1970-01-01T00:00:00 UTC``
354+
to ``1970-01-01T00:00:00 TAI`` to match the intended and documented behaviour.
355+
This essentially changes the resulting times by 8.000082 seconds, the initial
356+
offset between TAI and UTC. [#11249]
357+
358+
353359
astropy.timeseries
354360
^^^^^^^^^^^^^^^^^^
355361

@@ -379,6 +385,11 @@ Other Changes and Additions
379385
---------------------------
380386

381387

388+
- Change epoch of ``TimeUnixTAI`` (``"unix_tai"``) from ``1970-01-01T00:00:00 UTC``
389+
to ``1970-01-01T00:00:00 TAI`` to match the intended and documented behaviour.
390+
This essentially changes the resulting times by 8.000082 seconds, the initial
391+
offset between TAI and UTC. [#11249]
392+
382393

383394
4.2 (2020-11-24)
384395
================

‎astropy/time/formats.py‎

Lines changed: 27 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 leap seconds.
694694
695695
For example, 946684800.0 in Unix time is midnight on January 1, 2000.
696696
@@ -710,38 +710,53 @@ 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 1972-01-01 UTC
717+
plus the initial offset of 10 seconds at that date.
718+
719+
This convention matches the definition of linux CLOCK_TAI
720+
(https://www.cl.cam.ac.uk/~mgk25/posix-clocks.html),
721+
and the Precision Time Protocol
722+
(https://en.wikipedia.org/wiki/Precision_Time_Protocol), which
723+
is also used by the White Rabbit protocol in High Energy Physics:
724+
https://white-rabbit.web.cern.ch.
718725
719726
Caveats:
720727
721728
- Before 1972, fractional adjustments to UTC were made, so the difference
722729
between ``unix`` and ``unix_tai`` time is no longer an integer.
723730
- 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
731+
is the number of seconds since ``1970-01-01 00:00:00 TAI`` or equivalently
732+
``1969-12-31 23:59:51.999918 UTC``. The difference between TAI and UTC
726733
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
734+
- On the day of a positive leap second the difference between ``unix`` and
735+
``unix_tai`` times increases linearly through the day by 1.0. See also the
729736
documentation for the `~astropy.time.TimeUnix` class.
737+
- Negative leap seconds are possible, though none have been needed to date.
730738
731739
Examples
732740
--------
733741
742+
>>> # get the current offset between TAI and UTC
734743
>>> from astropy.time import Time
735744
>>> t = Time('2020-01-01', scale='utc')
736745
>>> t.unix_tai - t.unix
737-
29.0
746+
37.0
738747
748+
>>> # Before 1972, the offset between TAI and UTC was not integer
739749
>>> t = Time('1970-01-01', scale='utc')
740750
>>> t.unix_tai - t.unix # doctest: +FLOAT_CMP
741-
8.200000198854696e-05
751+
8.000082
752+
753+
>>> # Initial offset of 10 seconds in 1972
754+
>>> t = Time('1972-01-01', scale='utc')
755+
>>> t.unix_tai - t.unix
756+
10.0
742757
"""
743758
name = 'unix_tai'
744-
epoch_val = '1970-01-01 00:00:08'
759+
epoch_val = '1970-01-01 00:00:00'
745760
epoch_scale = 'tai'
746761

747762

‎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)