# tai_from_utc¶

lsst.ts.salobj.tai_from_utc(utc, format='unix')

Return TAI in unix seconds, given UTC or any astropy.time.Time.

Parameters: utc : UTC time in the specified format. format : Format of the UTC time, as an astropy.time format name, or None to have astropy guess. Ignored if utc is an instance of astropy.time.Time. tai_unix : float TAI time in unix seconds. ValueError If the date is earlier than 1972 (which is before integer leap seconds) or within one day of the expiration date of the leap second table (which is automatically updated).

Notes

If you have UTC in floating point format and performance is an issue, please call tai_from_utc_unix to avoid the overhead of converting your time to an astropy.time.Time.

This function will be deprecated once we upgrade to a version of astropy that supports TAI seconds. tai_from_utc_unix will remain.

Leap Seconds on the Day Before a Leap Second

This routine may not behave as you expect on the day before a leap second. Specify the date in ISO format if you want the correct answer.

When UTC is expressed as unix time, Julian Day, or Modified Julian Day the answer is ambiguous, so the result can be off by up to a second from what you might expect. This function follows astropy.time and Standards of Fundamental Astronomy (SOFA) by shrinking or stretching unix time, Julian Day, and Modified Julian Day, as needed, so that exactly one day of 86400 seconds (of modified duration) elapses. This leads to TAI-UTC varying continuously on that day, instead of being an integer number of seconds. See https://github.com/astropy/astropy/issues/10055

Also note that the behavior of the unix clock is not well defined on the day before a leap second. Both ntp and ptp can be configured to make the clock jump or smear in some way. https://developers.redhat.com/blog/2016/12/28/leap-second-i-belong-to-you/

In theory the datetime format could work as well as ISO format, but in practice it does not. The datetime library does not handle leap seconds, and the datetime representation in astropy.time raises an exception if the date has 60 in the seconds field.

On Linux an excellent way to get current TAI on the day of a leap second is to configure ntp or ptp to maintain a leap second table, then use the CLOCK_TAI clock (which is only available on Linux).

The leap second table is automatically updated.