Converting a UTC date and time to TAI
In order to convert a UTC date and time to TAI, you must first
obtain the leap second data by using one of the methods described
in Obtaining a list of leap seconds. Then, you can use the
LeapSecondData.to_tai() method to convert the date and time.
For example:
from datetime import timezone, datetime
from leapseconddata import LeapSecondData
my_date = datetime(2024, 7, 18, 22, 0, 0, tzinfo=timezone.utc)
data = LeapSecondData.from_standard_source()
my_tai_date = data.to_tai(my_date)
print(my_tai_date.isoformat())
This program will provide you with the following output:
2024-07-18T22:00:37+00:00