Skip to content

Time Representation

satkit.time is an instant with microsecond resolution that converts between the UTC, TAI, TT, TDB, UT1 and GPS time scales; satkit.duration is a time interval. What the scales are, how leap seconds and Earth orientation data enter, and which scale each part of the library uses are explained, with runnable examples, in Time Systems.

Python datetime interoperability

All functions in the satkit package that take time as an input accept either the satkit.time class or the more commonly-used datetime.datetime class, as well as a numpy.datetime64 (see below). Functions that take many times accept a list or 1-D numpy object array of any of these, or a 1-D numpy.datetime64 array. A datetime.datetime is converted with Python's own convention (datetime.timestamp()):

  • A naive datetime (no tzinfo) is interpreted in the machine's local time zone, not UTC.
  • An aware datetime uses its own UTC offset.

For UTC, pass tzinfo=datetime.timezone.utc or build a satkit.time directly. satkit.time.to_datetime() returns an aware UTC datetime; to_datetime(utc=False) returns a naive local-time datetime, which round-trips through satkit.time.from_datetime. Both directions are exact to the microsecond.

import datetime
import satkit as sk

sk.time.from_datetime(datetime.datetime(2024, 6, 15, 12, 30, tzinfo=datetime.timezone.utc))
# 2024-06-15T12:30:00.000000Z, on any machine

sk.time.from_datetime(datetime.datetime(2024, 6, 15, 12, 30))
# 12:30 local time: 2024-06-15T16:30:00.000000Z on a machine set to US Eastern (EDT)

numpy datetime64

A numpy.datetime64 scalar, or a 1-D datetime64 array of any unit (years through attoseconds), is read as a UTC label. numpy's datetime64 has no time zone and no leap seconds, so unlike a naive datetime it is never local time; it is converted exactly as an aware-UTC datetime with the same fields would be, including the pre-1972 UTC model. Like a datetime, it cannot name a leap second (23:59:60).

  • Values finer than a microsecond round to the nearest microsecond; a value exactly halfway goes to the later microsecond.
  • Year and month units go through the calendar (a datetime64[M] is the first of its month).
  • NaT raises ValueError, and a value beyond satkit's range (about ±292,000 years) raises OverflowError; both name the array index.
  • An array is read as its int64 counts, not element by element, which makes large time arrays cheap to build and pass: np.arange or arithmetic on a datetime64 array replaces a Python loop over satkit.time objects.
import numpy as np
import satkit as sk

tle = sk.TLE.from_lines([
    "1 25544U 98067A   24001.50000000  .00016717  00000-0  10270-3 0  9005",
    "2 25544  51.6400 208.9163 0006317  69.9862  25.2906 15.49560000 00001",
])[0]
times = np.datetime64("2024-01-01T12:00") + np.arange(1440) * np.timedelta64(1, "m")
pos, vel = sk.sgp4(tle, times)  # one day at one-minute steps, shape (1440, 3)

sk.frametransform.gmst(np.datetime64("2024-01-01T12:00:00.5"))  # scalars work too

Arithmetic, comparisons and formatting

A satkit.time orders against a datetime.datetime or numpy.datetime64 on either side (<, <=, >, >=), and subtracting one from the other gives a satkit.duration; the other operand is converted as time(other) would convert it. == is True only between two satkit.time objects, since a time and a datetime could not hash alike: convert first with time(dt). Durations can be a satkit.duration, datetime.timedelta or numpy.timedelta64 (scalar or 1-D array, any fixed unit, exact to the microsecond). An f-string format spec is a strftime format.

import datetime
import numpy as np
import satkit as sk

t = sk.time(2024, 1, 1, 12, 0, 0)
t < np.datetime64("2024-01-02")                                      # True
t - datetime.datetime(2024, 1, 1, tzinfo=datetime.timezone.utc)      # 12 hours
t + np.timedelta64(90, "s")                                          # 2024-01-01T12:01:30.000000Z
f"{t:%Y-%m-%d %H:%M}"                                                # '2024-01-01 12:00'
sk.duration.from_hours(5) // sk.duration.from_hours(2)               # 2
t.to_gregorian(scale=sk.timescale.TAI)                               # (2024, 1, 1, 12, 0, 37.0)
t.to_gps_week_and_second()                                           # (2295, 129618.0)

timescale

Specify time scale used to represent or convert between the "satkit.time" representation of time

Most of the time, these are not needed directly, but various time scales are needed to compute precise rotations between various inertial and Earth-fixed coordinate frames

The scales follow Chapter 10 of the IERS Conventions (2010), IERS Technical Note 36 (https://iers-conventions.obspm.fr/content/tn36.pdf); UTC and leap seconds are defined by ITU-R TF.460-6. For an excellent overview, see: https://spsweb.fltops.jpl.nasa.gov/portaldataops/mpg/MPG_Docs/MPG%20Book/Release/Chapter2-TimeScales.pdf

Values:

  • Invalid: placeholder that is not a time scale. Passing it as a scale argument raises ValueError
  • UTC: Universal Time Coordinate
  • TT: Terrestrial Time
  • UT1: UT1
  • TAI: International Atomic Time
  • GPS: Global Positioning System (GPS) time
  • TDB: Barycentric Dynamical Time

Invalid class-attribute

Placeholder that is not a time scale

Every satkit.time method that takes a scale raises ValueError when given it.

UTC class-attribute

Universal Time Coordinate

TT class-attribute

Terrestrial Time

UT1 class-attribute

UT1

TAI class-attribute

International Atomic Time (nice because it is monotonically increasing)

GPS class-attribute

Global Positioning System (GPS) time

TDB class-attribute

Barycentric Dynamical Time

__int__()

The integer value of the member (members also compare equal to it)

time

Representation of an instant in time

This has functionality similar to the "datetime" object, and in fact has the ability to convert to an from the "datetime" object. However, a separate time representation is needed as the "datetime" object does not allow for conversion between various time epochs (GPS, TAI, UTC, UT1, etc...)

Notes
  • If no arguments are passed in, the created object represents the current time
  • If year is passed in, month and day must also be passed in
  • If hour is passed in, minute and second must also be passed in
  • UTC before 1972 follows the "rubber second" model of USNO tai-utc.dat / ERFA dat from 1961-01-01: TAI - UTC drifts linearly and steps by fractions of a second (positive steps are labelled 23:59:60.x). Before 1961, UTC is taken to equal TAI (unlike ERFA, which also models 1960).
Example
print(satkit.time(2023, 3, 5, 11, 3, 45.453))
# 2023-03-05T11:03:45.453000Z

print(satkit.time(2023, 3, 5))
# 2023-03-05T00:00:00.000000Z

J2000 instance-attribute

The J2000 epoch: 2000-01-01 12:00:00 TT (class constant, read-only)

GPS_EPOCH instance-attribute

The GPS epoch: 1980-01-06 00:00:00 UTC (class constant, read-only)

MJD_EPOCH instance-attribute

The Modified Julian Date epoch: 1858-11-17 00:00:00 UTC (class constant, read-only)

UNIX_EPOCH instance-attribute

The Unix epoch: 1970-01-01 00:00:00 UTC (class constant, read-only)

weekday property

Day of the week (UTC)

day_of_year property

The 1-based Gregorian day of the year (1 = January 1, 365 = December 31)

now() staticmethod

Create a "time" object representing the instant of time at the calling of the function.

Returns:

Type Description
time

Time object representing the current time

from_string(string) staticmethod

Create a "time" object from a string, guessing its format

RFC 3339 is tried first (see from_rfc3339). Otherwise the numbers in the string are read in year, month, day, hour, minute, second order, so ISO-ordered strings ("2024-01-04 13:14:12.123") and month-name strings ("March 4 2024") work, but locale-ordered dates such as MM/DD/YYYY are not supported: use strptime for those.

Parameters:

Name Type Description Default
string str

String representation of time

required
Notes
  • A number after . following the seconds is the fraction of a second, rounded to the nearest microsecond.
  • A number after + or - following the minutes is a UTC offset (±HHMM, ±HH:MM or ±HH; hours 00-23, minutes 00-59) and is applied: "2024-01-04 13:14:12 +0100" is 12:14:12Z. Any other extra number is an error.
  • Seconds default to 0 ("2024-01-04 13:14"); an hour without minutes is an error, and a date alone is midnight.
  • Words other than month names (weekday names, T, Z, UTC, ...) are ignored, so a zone name is not applied: without a numeric offset the time is UTC.
  • This is probably not what you want. Use with caution, and prefer from_rfc3339 or strptime when the format is known.

Returns:

Type Description
time

Time object representing input string

Raises:

Type Description
ValueError

If the string cannot be parsed; the message gives the reason

Example
print(satkit.time.from_string("2023-03-05 11:03:45.453Z"))
# 2023-03-05T11:03:45.453000Z

from_rfc3339(rfc3339) staticmethod

Create a "time" object from an RFC 3339 string

Parameters:

Name Type Description Default
rfc3339 str

RFC 3339 string representation of time

required
Notes
  • Format YYYY-MM-DDTHH:MM:SS[.fff...][zone]. T may be t. The fraction has one or more digits and is rounded to the nearest microsecond beyond six. Surrounding whitespace is ignored; anything else left over is an error.
  • The zone is Z / z, or a UTC offset ±HH:MM (RFC 3339), ±HHMM or ±HH (ISO 8601 forms, also accepted), with hours 00-23 and minutes 00-59. The offset is applied: 2024-01-01T12:00:00+01:00 is 11:00:00Z. It shifts the calendar label, so it is exact across a leap second.
  • Without a zone the time is taken as UTC (RFC 3339 itself requires one).
  • The year is four digits, or a sign and at least four digits (ISO 8601 expanded years such as -0001 or +10000, as to_rfc3339 writes them outside 0000-9999).

Returns:

Type Description
time

Time object representing input RFC 3339 string

Raises:

Type Description
ValueError

If the string cannot be parsed; the message gives the reason

Example
print(satkit.time.from_rfc3339("2023-03-05T11:03:45.453Z"))
# 2023-03-05T11:03:45.453000Z

print(satkit.time.from_rfc3339("2023-03-05T12:03:45.453+01:00"))
# 2023-03-05T11:03:45.453000Z

strptime(date_string, format) staticmethod

Create a "time" object from input string with given formatting

Parameters:

Name Type Description Default
date_string str

string representation of time

required
format str

format of the string

required
Notes
  • The format string is a subset of the strptime format string in the Python "datetime" module. Characters other than format codes must match literally, and the whole string must be consumed: leftover input is an error.
  • Format Codes:
    • %Y - year: exactly four digits, or a sign and at least four digits (ISO 8601 expanded years such as -0044 or +10000, as strftime writes them outside 0000-9999)
    • %m - month, exactly two digits (01-12)
    • %d - day of month, exactly two digits (01-31)
    • %H - hour, exactly two digits (00-23)
    • %M - minute, exactly two digits (00-59)
    • %S - second, exactly two digits (00-59, or 60 in a leap second)
    • %f - fraction of a second: one or more digits (5 is 500 ms), rounded to the nearest microsecond beyond six
    • %b - abbreviated month name (Jan, Feb, ...)
    • %B - full month name (January, February, ...)
    • %z - UTC offset ±HH:MM, ±HHMM or ±HH (exactly two digits per field, hours 00-23, minutes 00-59), or Z / z for UTC. +HHMM means local time is ahead of UTC, so 12:00:00+0100 is 11:00:00Z; the offset shifts the calendar label, so it is exact across a leap second
    • %% - a literal %

Returns:

Type Description
time

Time object representing input string

Raises:

Type Description
ValueError

If the string does not match the format; the message gives the reason

Example
# %f reads any number of fraction digits: ".453" is 453 ms
print(satkit.time.strptime("2023-03-05 11:03:45.453Z", "%Y-%m-%d %H:%M:%S.%fZ"))
# 2023-03-05T11:03:45.453000Z

from_date(year, month, day, scale=timescale.UTC) staticmethod

Return a time object representing the start of the input day (midnight)

Parameters:

Name Type Description Default
year int

Gregorian year (e.g., 2024)

required
month int

Gregorian month (1 = January, 2 = February, ...)

required
day int

Day of month, beginning with 1

required
scale timescale

Time scale in which the date is given (midnight in that scale). Default is satkit.timescale.UTC

UTC

Returns:

Type Description
time

Time object representing the start of the input day (midnight)

Raises:

Type Description
TypeError

If an argument is not an integer

ValueError

If the month or day is out of range, the date is beyond about ±292,000 years, or scale is timescale.Invalid

Example
t = satkit.time.from_date(2023, 6, 15)
print(t)
# 2023-06-15T00:00:00.000000Z
# Midnight TAI is 37 s before midnight UTC
print(satkit.time.from_date(2023, 6, 15, scale=satkit.timescale.TAI))
# 2023-06-14T23:59:23.000000Z

from_jd(jd, scale=timescale.UTC) staticmethod

Return a time object representing input Julian date and time scale

Parameters:

Name Type Description Default
jd float

Julian date, days

required
scale timescale

Time scale. Default is satkit.timescale.UTC

UTC

Returns:

Type Description
time

Time object representing input Julian date and time scale

Raises:

Type Description
ValueError

If jd is NaN or infinite, or scale is timescale.Invalid

OverflowError

If the result is beyond about ±292,000 years

Example
t = satkit.time.from_jd(2460000.5)
print(t)

from_unixtime(unixtime) staticmethod

Return a time object representing input unixtime

Parameters:

Name Type Description Default
unixtime float

UTC seconds since Jan 1, 1970 00:00:00 (leap seconds are not included); rounded to the nearest microsecond

required

Returns:

Type Description
time

Time object representing input unixtime

Raises:

Type Description
ValueError

If unixtime is NaN or infinite

OverflowError

If the result is beyond about ±292,000 years

Example
t = satkit.time.from_unixtime(1700000000)
print(t)
# 2023-11-14T22:13:20.000000Z

from_gps_week_and_second(week, seconds) staticmethod

Return a time object representing input GPS week and second

Parameters:

Name Type Description Default
week int

GPS week number, counted from the GPS epoch (1980-01-06) without the 1024-week rollover

required
seconds float

GPS seconds of week, seconds; rounded to the nearest microsecond. Not limited to one week: 604800 is the start of the next week

required

Returns:

Type Description
time

Time object representing input GPS week and second

Raises:

Type Description
ValueError

If seconds is NaN or infinite

OverflowError

If the result is beyond about ±292,000 years

to_gps_week_and_second()

GPS week and seconds of week: the inverse of from_gps_week_and_second

Returns:

Type Description
tuple[int, float]

Tuple of the GPS week number, counted from the GPS epoch (1980-01-06) without the 1024-week rollover (negative before the epoch), and the GPS seconds of week in [0, 604800), the float nearest the exact (whole-microsecond) value

Example
week, sow = satkit.time(2024, 1, 1).to_gps_week_and_second()
print(week, sow)
# 2295 86418.0

from_mjd(mjd, scale=timescale.UTC) staticmethod

Return a time object representing input modified Julian date and time scale

Parameters:

Name Type Description Default
mjd float

Modified Julian date, days

required
scale timescale

Time scale. Default is satkit.timescale.UTC

UTC

Returns:

Type Description
time

Time object representing input modified Julian date and time scale

Raises:

Type Description
ValueError

If mjd is NaN or infinite, or scale is timescale.Invalid

OverflowError

If the result is beyond about ±292,000 years

Example
t = satkit.time.from_mjd(60000.0)
print(t)

to_date(scale=timescale.UTC)

Return tuple representing the Gregorian date of the time object (UTC by default).

Parameters:

Name Type Description Default
scale timescale

Time scale of the date. Default is satkit.timescale.UTC

UTC

Returns:

Type Description
tuple[int, int, int]

Tuple with 3 elements representing the Gregorian year, month, and day of the time object. Fractional component of day are truncated. Month is in range [1,12]. Day is in range [1,31].

Raises:

Type Description
ValueError

If scale is timescale.Invalid

as_date()

Deprecated since 0.23, removed in 0.25. Use time.to_date.

to_gregorian(scale=timescale.UTC)

Return tuple representing the Gregorian date and time of the time object (UTC by default).

Parameters:

Name Type Description Default
scale timescale

Time scale of the date and time. Default is satkit.timescale.UTC. The inverse of from_gregorian with the same scale: exact for UTC, TAI, TT and GPS; UT1 and TDB are rounded to the nearest microsecond

UTC

Returns:

Type Description
tuple[int, int, int, int, int, float]

Tuple with 6 elements representing the Gregorian year, month, day, hour, minute, and second of the time object. Month is in range [1,12]. Day is in range [1,31]. The second is the float nearest the exact (whole-microsecond) value, in [0, 60); inside a UTC leap second it is in [60, 61).

Raises:

Type Description
ValueError

If scale is timescale.Invalid

Example
t = satkit.time(2024, 1, 1)
print(t.to_gregorian(scale=satkit.timescale.TAI))
# (2024, 1, 1, 0, 0, 37.0)

as_gregorian()

Deprecated since 0.23, removed in 0.25. Use time.to_gregorian.

from_gregorian(year, month, day, hour, min, sec, scale=timescale.UTC) staticmethod

Create time object from 6 input arguments representing Gregorian time (UTC by default).

Parameters:

Name Type Description Default
year int

Gregorian year

required
month int

Gregorian month (1 = January, 2 = February, ...)

required
day int

Day of month, beginning with 1

required
hour int

Hour of day, in range [0,23]

required
min int

Minute of hour, in range [0,59]

required
sec float

floating point second of minute, in range [0,60); up to 61 within a UTC leap second (e.g. 23:59:60.5 on 2016-12-31) or a pre-1972 positive UTC step. Rounded to the nearest microsecond

required
scale timescale

Time scale in which the components are given, as for time(year, ..., sec, scale=...). Default is satkit.timescale.UTC. Only UTC has leap seconds

UTC

Returns:

Type Description
time

Time object representing input Gregorian time

Raises:

Type Description
TypeError

If an argument is not a number (the first five must be integers)

ValueError

If a component is out of range (including a second of 60 or more where there is no leap second, and NaN), the date is beyond about ±292,000 years, or scale is timescale.Invalid

Example
print(satkit.time.from_gregorian(2023, 3, 5, 11, 3,45.453))
# 2023-03-05T11:03:45.453000Z

from_datetime(dt) staticmethod

Convert input "datetime.datetime" object to an "satkit.time" object representing the same instant in time

Follows Python's own convention (datetime.timestamp()):

  • A naive datetime (no tzinfo) is interpreted in the machine's local time zone, not UTC.
  • An aware datetime uses its own UTC offset.

For UTC, pass tzinfo=datetime.timezone.utc or build a satkit.time directly. The conversion is exact to the microsecond (it does not go through the float timestamp()), and so is to_datetime().

Parameters:

Name Type Description Default
dt datetime

"datetime.datetime" object to convert

required

Returns:

Type Description
time

Time object representing the same instant in time as the input "datetime.datetime" object

to_datetime(utc=True)

Convert object to "datetime.datetime" object representing same instant in time.

Parameters:

Name Type Description Default
utc bool

If True (default), return an aware datetime in UTC. If False, return a naive datetime in the machine's local time zone, which round-trips through time.from_datetime.

True

Returns:

Type Description
datetime

"datetime.datetime" object representing the same instant in time as the "satkit.time" object

Raises:

Type Description
OverflowError

If the time is outside the years 1 to 9999 that datetime.datetime can represent

Notes

datetime.datetime has no leap seconds: a time inside one (23:59:60.5) comes back as 23:59:59.5, as with Unix time.

Example
dt = satkit.time(2023, 6, 3, 6, 19, 34).to_datetime(True)
print(dt)
# 2023-06-03 06:19:34+00:00

dt = satkit.time(2023, 6, 3, 6, 19, 34).to_datetime(False)
print(dt)
# 2023-06-03 02:19:34

as_datetime(utc=True)

Deprecated since 0.23, removed in 0.25. Use time.to_datetime.

datetime(utc=True)

Deprecated: use satkit.time.to_datetime.

Convert object to "datetime.datetime" object representing same instant in time.

Parameters:

Name Type Description Default
utc bool

If True (default), return an aware datetime in UTC. If False, return a naive datetime in the machine's local time zone, which round-trips through time.from_datetime.

True

Returns:

Type Description
datetime

"datetime.datetime" object representing the same instant in time as the "satkit.time" object

Example
dt = satkit.time(2023, 6, 3, 6, 19, 34).datetime(True)
print(dt)
# 2023-06-03 06:19:34+00:00

dt = satkit.time(2023, 6, 3, 6, 19, 34).datetime(False)
print(dt)
# 2023-06-03 02:19:34

add_utc_days(days)

Return a new time offset by a number of UTC calendar days.

The offset is applied to the UTC clock label (as with a Modified Julian Date in UTC), so the time of day is kept: noon plus one UTC day is noon of the next day, which is 86401 elapsed seconds later when a leap second lies between the two. days may be fractional (a fraction of 86400 s on the label) or negative.

To add exactly 86400 elapsed seconds per day instead, use t + days or t + satkit.duration(days=days).

Parameters:

Name Type Description Default
days float

Number of UTC days to add; rounded to the nearest microsecond

required

Returns:

Type Description
time

Time object offset by the given number of UTC days

Raises:

Type Description
ValueError

If days is NaN or infinite

OverflowError

If the result is beyond about ±292,000 years

Example
t = satkit.time(2016, 12, 31, 12, 0, 0)  # a leap second follows
print(t.add_utc_days(1))
# 2017-01-01T12:00:00.000000Z
print(t + 1)
# 2017-01-01T11:59:59.000000Z

to_mjd(scale=timescale.UTC)

Represent time instance as a Modified Julian Date with the provided time scale

If no time scale is provided, default is satkit.timescale.UTC

Returns:

Type Description
float

Modified Julian Date, days

Raises:

Type Description
ValueError

If scale is timescale.Invalid

as_mjd(scale=timescale.UTC)

Deprecated since 0.23, removed in 0.25. Use time.to_mjd.

to_jd(scale=timescale.UTC)

Represent time instance as Julian Date with the provided time scale

If no time scale is provided, default is satkit.timescale.UTC

Returns:

Type Description
float

Julian Date, days

Raises:

Type Description
ValueError

If scale is timescale.Invalid

as_jd(scale=timescale.UTC)

Deprecated since 0.23, removed in 0.25. Use time.to_jd.

to_unixtime()

Represent time as unixtime

(seconds since Jan 1, 1970 UTC, excluding leap seconds)

Includes fractional component of seconds. The result is the float nearest the exact (whole-microsecond) value, so it prints as the decimal it was built from: time.from_unixtime(1678014225.453) gives back 1678014225.453. Inside a leap second it repeats the last second of the day.

Returns:

Type Description
float

Unix time, seconds

as_unixtime()

Deprecated since 0.23, removed in 0.25. Use time.to_unixtime.

to_iso8601()

Represent time as ISO 8601 string

The fraction always has six digits (microseconds). Years outside 0000-9999 are written with a sign and at least four digits, as in ISO 8601 expanded years: -0044-03-15T..., +10000-01-01T.... to_iso8601 and to_rfc3339 return the same string.

Returns:

Type Description
ISO 8601 string representation of time

"YYYY-MM-DDTHH:MM:SS.ssssssZ"

as_iso8601()

Deprecated since 0.23, removed in 0.25. Use time.to_iso8601.

to_rfc3339()

Represent time as RFC 3339 string

The fraction always has six digits (microseconds). Years outside 0000-9999 are written with a sign and at least four digits, as in ISO 8601 expanded years: -0044-03-15T..., +10000-01-01T.... to_iso8601 and to_rfc3339 return the same string.

Returns:

Type Description
RFC 3339 string representation of time

"YYYY-MM-DDTHH:MM:SS.ssssssZ"

as_rfc3339()

Deprecated since 0.23, removed in 0.25. Use time.to_rfc3339.

strftime(format)

Represent time as string with given format

Parameters:

Name Type Description Default
format str

format of the string

required
Notes

The time is written in UTC. Format codes (a subset of Python's; there is no %z, %j, %y or %p):

  • %Y - year, four digits (0000-9999); outside that range a sign and at least four digits (-0044, +10000)
  • %m - month with leading zeros (01-12)
  • %d - day of month with leading zeros (01-31)
  • %H - hour with leading zeros (00-23)
  • %M - minute with leading zeros (00-59)
  • %S - second with leading zeros (00-59, or 60 inside a leap second)
  • %f - microsecond, always six digits (000000-999999)
  • %b - abbreviated month name (Jan, Feb, ...)
  • %B - full month name (January, February, ...)
  • %a - abbreviated weekday name (Sun, Mon, ...)
  • %A - full weekday name (Sunday, Monday, ...)
  • %w - weekday as a decimal number (0=Sunday, 1=Monday, ...)
  • %% - a literal %

Returns:

Type Description
str

string representation of time

Raises:

Type Description
ValueError

If the format has a code not listed above, or ends with a lone %

Example
print(satkit.time(2023, 6, 3, 6, 19, 34).strftime("%Y-%m-%d %H:%M:%S"))
# 2023-06-03 06:19:34

__format__(format_spec)

Format the time for an f-string or format()

An empty spec gives str(t); any other spec is a strftime format (see strftime for the codes).

Parameters:

Name Type Description Default
format_spec str

format spec

required

Returns:

Type Description
str

The formatted time

Raises:

Type Description
ValueError

If the spec has a code strftime does not support

Example
t = satkit.time(2023, 6, 3, 6, 19, 34)
print(f"{t:%Y-%m-%d}")
# 2023-06-03
print(f"{t}")
# 2023-06-03T06:19:34.000000Z

__radd__(other)

datetime.timedelta + time or numpy.timedelta64 + time: the time other later

Parameters:

Name Type Description Default
other timedelta | timedelta64

time difference to add

required

Raises:

Type Description
ValueError

if a timedelta64 is NaT or in years or months

OverflowError

if the result is beyond about ±292,000 years

Returns:

Type Description
time

Time object representing the current time plus the timedelta

__le__(other)

Compare for less than or equal to

The ordering operators (<, <=, >, >=) take a satkit.time, datetime.datetime or numpy.datetime64, converted as time(other) (a naive datetime is local time; a datetime64 is UTC), on either side. Ordering against any other type raises TypeError. == is True only between two satkit.time objects.

Parameters:

Name Type Description Default
other time | datetime | datetime64

time to compare with

required

Raises:

Type Description
ValueError

if other is NaT

Returns:

Type Description
bool

True if "self" time is less than or equal to "other" time, False otherwise

__lt__(other)

Compare for less than

Parameters:

Name Type Description Default
other time | datetime | datetime64

time to compare with, converted as time(other)

required

Raises:

Type Description
ValueError

if other is NaT

Returns:

Type Description
bool

True if "self" time is less than "other" time, False otherwise

__ge__(other)

Compare for greater than or equal to

Parameters:

Name Type Description Default
other time | datetime | datetime64

time to compare with, converted as time(other)

required

Raises:

Type Description
ValueError

if other is NaT

Returns:

Type Description
bool

True if "self" time is greater than or equal to "other" time, False otherwise

__gt__(other)

Compare for greater than

Parameters:

Name Type Description Default
other time | datetime | datetime64

time to compare with, converted as time(other)

required

Raises:

Type Description
ValueError

if other is NaT

Returns:

Type Description
bool

True if "self" time is greater than "other" time, False otherwise

__eq__(value)

Compare two time objects for equality

Only another satkit.time can be equal: time == datetime is False even for the same instant, as the two could not hash alike. Convert first with time(dt).

Parameters:

Name Type Description Default
value object

object to compare with

required

Returns:

Type Description
bool

True if "self" time is equal to "value", False otherwise

__ne__(value)

Compare two time objects for inequality

Parameters:

Name Type Description Default
value object

object to compare with

required

Returns:

Type Description
bool

True if "self" time is not equal to "value", False otherwise

__rsub__(other)

datetime.datetime - time or numpy.datetime64 - time: the difference, with other converted as time(other)

Parameters:

Name Type Description Default
other datetime | datetime64

time to subtract from

required

Raises:

Type Description
ValueError

if other is NaT

OverflowError

if the difference is beyond about ±292,000 years

Returns:

Type Description
duration

Duration time(other) - self

__init__(year, month, day, hour, min, sec, /, *, scale=timescale.UTC)

__init__() -> None
__init__(string: str) -> None
__init__(t: time | datetime.datetime | np.datetime64) -> None
__init__(year: int, month: int, day: int, /, *, scale: timescale = timescale.UTC) -> None
__init__(year: int, month: int, day: int, hour: int, min: int, sec: float, /, *, scale: timescale = timescale.UTC) -> None

Create a time object representing input date and time

This has functionality similar to the "datetime" object, and in fact has the ability to convert to an from the "datetime" object. However, a separate time representation is needed as the "datetime" object does not allow for conversion between various time epochs (GPS, TAI, UTC, UT1, etc...)

Accepted forms (all positional):

  • time(): the current time
  • time(string): parse a string, RFC 3339 first (e.g. "2023-03-05T11:03:45.453Z"), then other common formats
  • time(t): the instant of another satkit.time, a datetime.datetime or a numpy.datetime64
  • time(year, month, day): midnight at the start of the day
  • time(year, month, day, hour, min, sec): all six components

Parameters:

Name Type Description Default
string

String representation of time

required
t

A satkit.time (copied), a datetime.datetime (as in from_datetime: a naive one is the machine's local time, an aware one uses its own offset) or a numpy.datetime64 (a UTC label; NaT raises ValueError)

required
year int

Gregorian year (e.g., 2024)

required
month int

Gregorian month (1 = January, 2 = February, ...)

required
day int

Day of month, beginning with 1

required
hour int

Hour of day, in range [0,23]

required
min int

Minute of hour, in range [0,59]

required
sec float

Floating point second of minute, in range [0,60); up to 61 within a UTC leap second (e.g. 23:59:60.5 on 2016-12-31), and within a pre-1972 positive UTC step (e.g. 23:59:60.05 on 1963-10-31, up to 61.422818 on 1960-12-31). Rounded to the nearest microsecond, so the seconds from to_gregorian() round-trip exactly

required
scale timescale

Time scale in which the Gregorian components are interpreted, default is satkit.timescale.UTC. Only for the (year, month, day) and six-component forms: giving it with the string or no-argument form raises TypeError.

UTC

Raises:

Type Description
TypeError

If the number of positional arguments is not 0, 1, 3 or 6; if a single argument is not a string or a time; if a component is not a number (the first five must be integers); or if scale is given with the string or no-argument form

ValueError

If the string form cannot be parsed, if a component is out of range (month 13, hour 25, a second of 60 where there is no leap second, NaN, ...), if the date is beyond about ±292,000 years, or if scale is timescale.Invalid

Example
print(satkit.time(2023, 3, 5, 11, 3, 45.453))
# 2023-03-05T11:03:45.453000Z

print(satkit.time(2023, 3, 5))
# 2023-03-05T00:00:00.000000Z

import datetime
print(satkit.time(datetime.datetime(2023, 3, 5, tzinfo=datetime.timezone.utc)))
# 2023-03-05T00:00:00.000000Z

__add__(other)

__add__(other: duration | _TimeDelta | np.timedelta64) -> time
__add__(other: float) -> time
__add__(other: list[duration] | npt.NDArray[np.timedelta64]) -> npt.NDArray[Any]
__add__(other: npt.NDArray[np.floating[Any]] | npt.NDArray[np.integer[Any]] | list[float] | list[int]) -> npt.NDArray[Any]
__add__(other: duration | _TimeDelta | np.timedelta64) -> time

Return a time object representing the input duration added to the current time

Parameters:

Name Type Description Default
other duration | timedelta | timedelta64

duration to add to the current time (a timedelta is exact, and so is a timedelta64 in whole microseconds or coarser; finer units round to the nearest microsecond; timedelta + time works too)

required

Raises:

Type Description
ValueError

if a timedelta64 is NaT or in years or months

OverflowError

if the result is beyond about ±292,000 years

Returns:

Type Description
time

Time object representing the input duration added to the current time

__add__(other: float) -> time

Return a time object representing the input number of days added to the current time

Each day is exactly 86400 elapsed seconds, so across a leap second the UTC time of day shifts by one second; add_utc_days keeps the UTC time of day instead.

Parameters:

Name Type Description Default
other float

number of days to add to the current time

required

Raises:

Type Description
ValueError

if other is NaN or infinite

OverflowError

if other is too large for a duration, or the result is beyond about ±292,000 years

Returns:

Type Description
time

Time object representing the input number of days added to the current time

__add__(other: list[duration] | npt.NDArray[np.timedelta64]) -> npt.NDArray[Any]

Return a numpy array of time objects, with each object representing an element-wise addition of days to the "self" time object

Parameters:

Name Type Description Default
other list[duration] | NDArray[timedelta64]

list of durations (a list, not any sequence: a tuple is refused), or a 1-D numpy timedelta64 array of any fixed unit (exact to the microsecond), to add to the current time

required

Raises:

Type Description
ValueError

if a timedelta64 element is NaT, the array is not 1-D, or its unit is years or months

OverflowError

if a result is beyond about ±292,000 years

Returns:

Type Description
NDArray[Any]

Object array of time objects, self + other[i] for each element

__add__(other: npt.NDArray[np.floating[Any]] | npt.NDArray[np.integer[Any]] | list[float] | list[int]) -> npt.NDArray[Any]

Return a numpy array of time objects, with each object representing an element-wise addition of days to the "self" time object

Parameters:

Name Type Description Default
other NDArray[floating] | NDArray[integer] | list[float]

1-D array or list of days to add to the current time (integer and float32 arrays are converted to float64)

required

Raises:

Type Description
ValueError

if an element is NaN or infinite

OverflowError

if an element is too large for a duration, or a result is beyond about ±292,000 years

Returns:

Type Description
NDArray[Any]

Object array of time objects representing the element-wise addition of days to the current time

__sub__(other)

__sub__(other: duration | _TimeDelta | np.timedelta64) -> time
__sub__(other: time | _DateTime | np.datetime64) -> duration
__sub__(other: float) -> time
__sub__(other: npt.NDArray[np.floating[Any]] | npt.NDArray[np.integer[Any]] | list[float] | list[int]) -> npt.NDArray[Any]
__sub__(other: list[duration] | npt.NDArray[np.timedelta64]) -> npt.NDArray[Any]
__sub__(other: list[time]) -> npt.NDArray[Any]
__sub__(other: duration | _TimeDelta | np.timedelta64) -> time

Return a time object representing the input duration subtracted from the current time

Parameters:

Name Type Description Default
other duration | timedelta | timedelta64

duration to subtract from the current time (a timedelta is exact, and so is a timedelta64 in whole microseconds or coarser)

required

Raises:

Type Description
ValueError

if a timedelta64 is NaT or in years or months

OverflowError

if the result is beyond about ±292,000 years

Returns:

Type Description
time

Time object representing the input duration subtracted from the current time

__sub__(other: time | _DateTime | np.datetime64) -> duration

Return a duration object representing the difference between the two times

Parameters:

Name Type Description Default
other time | datetime | datetime64

time to subtract from the current time, converted as time(other) (a naive datetime is local time; a datetime64 is UTC)

required

Raises:

Type Description
ValueError

if other is NaT

OverflowError

if the difference is beyond about ±292,000 years (only for times near the two ends of the range)

Returns:

Type Description
duration

Duration object representing the difference between the two times

__sub__(other: float) -> time

Return a time object representing the input number of days subtracted from the current time

Parameters:

Name Type Description Default
other float

number of days to subtract from the current time

required

Raises:

Type Description
ValueError

if other is NaN or infinite

OverflowError

if other is too large for a duration, or the result is beyond about ±292,000 years

Returns:

Type Description
time

Time object representing the input number of days subtracted from the current time

__sub__(other: npt.NDArray[np.floating[Any]] | npt.NDArray[np.integer[Any]] | list[float] | list[int]) -> npt.NDArray[Any]

Return a numpy array of time objects, with each object representing an element-wise subtraction of days from the "self" time object

Parameters:

Name Type Description Default
other NDArray[floating] | NDArray[integer] | list[float]

1-D array or list of days to subtract from the current time (integer and float32 arrays are converted to float64)

required

Raises:

Type Description
ValueError

if an element is NaN or infinite

OverflowError

if an element is too large for a duration, or a result is beyond about ±292,000 years

Returns:

Type Description
NDArray[Any]

Object array of time objects representing the element-wise subtraction of days from the current time

__sub__(other: list[duration] | npt.NDArray[np.timedelta64]) -> npt.NDArray[Any]

Return a numpy array of time objects, with each object representing an element-wise subtraction of duration from the "self" time object

Parameters:

Name Type Description Default
other list[duration] | NDArray[timedelta64]

list of durations (a list, not any sequence: a tuple is refused), or a 1-D numpy timedelta64 array of any fixed unit, to subtract from the current time

required

Raises:

Type Description
ValueError

if a timedelta64 element is NaT, the array is not 1-D, or its unit is years or months

OverflowError

if a result is beyond about ±292,000 years

Returns:

Type Description
NDArray[Any]

Object array of time objects, self - other[i] for each element

__sub__(other: list[time]) -> npt.NDArray[Any]

Return a numpy array of duration objects, with each object representing an element-wise subtraction of time from the "self" time object

Parameters:

Name Type Description Default
other list[time]

list of times to subtract from the current time (a list, not any sequence)

required

Raises:

Type Description
OverflowError

if a difference is beyond about ±292,000 years

Returns:

Type Description
NDArray[Any]

Object array of duration objects, self - other[i] for each element

duration

Representation of a duration, or interval of time

days property

Floating point number of days represented by duration

Returns:

Type Description
float

Floating point number of days represented by duration

A day is defined as 86,400 seconds

hours property

Floating point number of hours represented by duration

Returns:

Type Description
float

Floating point number of hours represented by duration

microseconds property

Number of whole microseconds represented by duration

Returns:

Type Description
int

Integer number of microseconds represented by duration

milliseconds property

Floating point number of milliseconds represented by duration

The whole duration, like seconds (the float nearest the exact value), not a component of it.

Returns:

Type Description
float

Floating point number of milliseconds represented by duration

minutes property

Floating point number of minutes represented by duration

Returns:

Type Description
float

Floating point number of minutes represented by duration

seconds property

Floating point number of seconds represented by duration

Returns:

Type Description
float

Floating point number of seconds represented by duration

__init__(*, days=0.0, hours=0.0, minutes=0.0, seconds=0.0, microseconds=0)

Create a duration object representing input time duration

Parameters:

Name Type Description Default
days float

Number of days, default is 0

0.0
hours float

Number of hours, default is 0

0.0
minutes float

Number of minutes, default is 0

0.0
seconds float

Number of seconds, default is 0.0

0.0
microseconds int

Number of microseconds (an integer), default is 0

0
Notes
  • If no arguments are passed in, the created object represents a duration of 0 seconds
  • A duration is an integer number of microseconds; each floating-point argument is rounded to the nearest microsecond
  • Adding or subtracting durations and times raises OverflowError when the result is beyond about ±292,000 years (it used to wrap around)
  • str() of a duration of a second or more lists the non-zero days, hours and minutes, then the seconds with six decimals; a shorter (or negative) one prints as whole microseconds (500000 usec)

Raises:

Type Description
TypeError

If an argument is not a real number, or microseconds is not an integer (the from_* constructors do the same)

ValueError

If an argument is NaN or infinite

OverflowError

If an argument is too large for a duration (beyond about ±292,000 years), or the arguments fit one by one but not summed

Example
print(satkit.duration(days=1, hours=2, minutes=3, seconds=4.5))
# 1 days 2 hours 3 minutes 4.500000 seconds

from_days(d) staticmethod

Create duration object given input number of days. Note: a day is defined as 86,400 seconds

Parameters:

Name Type Description Default
d float

Number of days

required

Returns:

Type Description
duration

Duration object representing input number of days

Example
d = satkit.duration.from_days(1.5)
print(d.hours)
# 36.0

from_seconds(seconds) staticmethod

Create duration object representing input number of seconds

Parameters:

Name Type Description Default
seconds float

Number of seconds

required

Returns:

Type Description
duration

Duration object representing input number of seconds

Example
d = satkit.duration.from_seconds(3600)
print(d.hours)
# 1.0

from_minutes(minutes) staticmethod

Create duration object representing input number of minutes

Parameters:

Name Type Description Default
minutes float

Number of minutes

required

Returns:

Type Description
duration

Duration object representing input number of minutes

from_hours(hours) staticmethod

Create duration object representing input number of hours

Parameters:

Name Type Description Default
hours float

Number of hours

required

Returns:

Type Description
duration

Duration object representing input number of hours

from_milliseconds(d) staticmethod

Create duration object representing input number of milliseconds

Parameters:

Name Type Description Default
d float

Number of milliseconds

required

Returns:

Type Description
duration

Duration object representing input number of milliseconds

from_microseconds(microseconds) staticmethod

Create duration object from a whole number of microseconds (exact)

Parameters:

Name Type Description Default
microseconds int

Number of microseconds

required

Returns:

Type Description
duration

Duration object representing input number of microseconds

Raises:

Type Description
TypeError

If microseconds is not an integer

OverflowError

If microseconds does not fit a signed 64-bit integer (about ±292,000 years)

Example
d = satkit.duration.from_microseconds(1500)
print(d.milliseconds)
# 1.5

from_timedelta(td) staticmethod

Create duration object from a datetime.timedelta

Exact: both count whole microseconds.

Parameters:

Name Type Description Default
td timedelta

The time difference

required

Returns:

Type Description
duration

Duration object representing the same interval

Raises:

Type Description
OverflowError

If td is beyond the range of a duration (about ±292,000 years; a timedelta reaches ±2.7 million)

Example
import datetime
d = satkit.duration.from_timedelta(datetime.timedelta(hours=1, microseconds=1))
print(d.microseconds)
# 3600000001

to_timedelta()

Convert to a datetime.timedelta

Exact: both count whole microseconds, and every duration fits.

Returns:

Type Description
timedelta

datetime.timedelta representing the same interval

Example
print(satkit.duration(hours=1, seconds=0.5).to_timedelta())
# 1:00:00.500000

__sub__(other)

Take the difference between two durations

Parameters:

Name Type Description Default
other duration

duration to subtract from the current duration

required

Raises:

Type Description
OverflowError

if the result is beyond about ±292,000 years

Returns:

Type Description
duration

Duration object representing the difference between the two durations

Example
print(satkit.duration.from_hours(1) - satkit.duration.from_minutes(1))
# 59 minutes 0.000000 seconds

__mul__(other)

Multiply (or scale) duration by given value

The product is computed exactly from the duration's integer microseconds and rounded once to the nearest microsecond, so an integer factor is exact for any duration.

Parameters:

Name Type Description Default
other float

value by which to multiply duration (any real number: int, float or a numpy scalar)

required

Returns:

Type Description
duration

Duration object representing the input duration scaled by the input value

Raises:

Type Description
ValueError

if other is NaN or infinite

OverflowError

if the result is beyond about ±292,000 years

Example
print(satkit.duration.from_days(1) * 2.5)
# 2 days 12 hours 0.000000 seconds

__rmul__(other)

Multiply (or scale) duration by given value: 2 * d is d * 2

Parameters:

Name Type Description Default
other float

value by which to multiply duration

required

Returns:

Type Description
duration

Duration object representing the input duration scaled by the input value

Raises:

Type Description
ValueError

if other is NaN or infinite

OverflowError

if the result is beyond about ±292,000 years

__neg__()

The duration with its sign reversed

Raises:

Type Description
OverflowError

for the most negative duration (-2**63 microseconds)

Example
print((-satkit.duration(hours=1)).hours)
# -1.0

__pos__()

The duration itself

__abs__()

The duration without its sign

Raises:

Type Description
OverflowError

for the most negative duration (-2**63 microseconds)

__mod__(other)

Remainder of floor division by a duration: self - (self // other) * other

Exact; like Python's %, the result has the sign of other (or is zero).

Parameters:

Name Type Description Default
other duration

duration divisor

required

Returns:

Type Description
duration

The remainder

Raises:

Type Description
ZeroDivisionError

if other is a zero duration

Example
print(satkit.duration.from_minutes(7) % satkit.duration.from_minutes(2))
# 1 minutes 0.000000 seconds

__gt__(other)

Compare two durations for greater than

Parameters:

Name Type Description Default
other duration

duration to compare with

required

Returns: True if "self" duration is greater than "other" duration, False otherwise

Example
print(satkit.duration.from_hours(1) > satkit.duration.from_minutes(30))
# True

__lt__(other)

Compare two durations for less than

Parameters:

Name Type Description Default
other duration

duration to compare with

required

Returns: True if "self" duration is less than "other" duration, False otherwise

Example
print(satkit.duration.from_hours(1) < satkit.duration.from_minutes(30))
# False

__ge__(other)

Compare two durations for greater than or equal to

Parameters:

Name Type Description Default
other duration

duration to compare with

required

Returns: True if "self" duration is greater than or equal to "other" duration, False otherwise

Example
print(satkit.duration.from_hours(1) >= satkit.duration.from_minutes(30))
# True

__le__(other)

Compare two durations for less than or equal to

Parameters:

Name Type Description Default
other duration

duration to compare with

required

Returns: True if "self" duration is less than or equal to "other" duration, False otherwise

Example
print(satkit.duration.from_hours(1) <= satkit.duration.from_minutes(30))
# False

__add__(other)

__add__(other: duration) -> duration
__add__(other: time) -> time
__add__(other: duration) -> duration

Add a duration to another duration

Parameters:

Name Type Description Default
other duration

duration to add to the current duration

required

Raises:

Type Description
OverflowError

if the result is beyond about ±292,000 years

Returns:

Type Description
duration

Duration object representing the sum, or concatenation, of both durations

Example
print(satkit.duration.from_hours(1) + satkit.duration.from_minutes(1))
# 1 hours 1 minutes 0.000000 seconds
__add__(other: time) -> time

Add a duration to a time

Parameters:

Name Type Description Default
other time

time to add the current duration to

required

Raises:

Type Description
OverflowError

if the result is beyond about ±292,000 years

Returns:

Type Description
time

Time object representing the input time plus the duration

Example
print(satkit.duration.from_hours(1) + satkit.time(2023, 6, 4, 11,30,0))
# 2023-06-04T12:30:00.000000Z

__truediv__(other)

__truediv__(other: float) -> duration
__truediv__(other: duration) -> float
__truediv__(other: float) -> duration

Divide (or scale) duration by given value

Parameters:

Name Type Description Default
other float

value by which to divide duration

required

Returns:

Type Description
duration

Duration object representing the input duration divided by the input value

Raises:

Type Description
ZeroDivisionError

if other is zero

ValueError

if other is NaN

OverflowError

if the result is beyond about ±292,000 years (division by a very small number)

Notes

The quotient is computed exactly from the duration's integer microseconds and rounded once to the nearest microsecond. Dividing by infinity gives a zero duration.

Example
print(satkit.duration.from_days(1) / 2)
# 12 hours 0.000000 seconds
__truediv__(other: duration) -> float

Divide (or scale) duration by another duration to get a dimensionless ratio

Parameters:

Name Type Description Default
other duration

duration by which to divide current duration

required

Returns:

Type Description
float

Dimensionless ratio of the two durations

Raises:

Type Description
ZeroDivisionError

if other is a zero duration

Example
print(satkit.duration.from_hours(1) / satkit.duration.from_minutes(30))
# 2.0

__floordiv__(other)

__floordiv__(other: duration) -> int
__floordiv__(other: float) -> duration
__floordiv__(other: duration) -> int

How many whole times other fits in the duration

Exact integer-microsecond arithmetic, floored as Python's // (towards negative infinity), so a == (a // b) * b + a % b.

Parameters:

Name Type Description Default
other duration

duration divisor

required

Returns:

Type Description
int

floor(self / other) as an int

Raises:

Type Description
ZeroDivisionError

if other is a zero duration

Example
print(satkit.duration.from_minutes(7) // satkit.duration.from_minutes(2))
# 3
__floordiv__(other: float) -> duration

Divide the duration by a real number, rounding down to a whole microsecond

The quotient is computed exactly from the duration's integer microseconds and floored (towards negative infinity).

Parameters:

Name Type Description Default
other float

value by which to divide the duration

required

Returns:

Type Description
duration

Duration of floor(self / other) microseconds

Raises:

Type Description
ZeroDivisionError

if other is zero

ValueError

if other is NaN or infinite

OverflowError

if the result is beyond about ±292,000 years

Example
print(satkit.duration(microseconds=7) // 2)
# 3 usec

weekday

Represent the day of the week

Values:

  • Sunday
  • Monday
  • Tuesday
  • Wednesday
  • Thursday
  • Friday
  • Saturday
  • Invalid: placeholder that is not a day; time.weekday never returns it

Sunday class-attribute

Sunday

Monday class-attribute

Monday

Tuesday class-attribute

Tuesday

Wednesday class-attribute

Wednesday

Thursday class-attribute

Thursday

Friday class-attribute

Friday

Saturday class-attribute

Saturday

Invalid class-attribute

Placeholder that is not a day of the week; time.weekday never returns it

__int__()

The integer value of the member (members also compare equal to it)