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). NaTraisesValueError, and a value beyond satkit's range (about ±292,000 years) raisesOverflowError; 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.arangeor arithmetic on adatetime64array replaces a Python loop oversatkit.timeobjects.
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 ascaleargument raisesValueErrorUTC: Universal Time CoordinateTT: Terrestrial TimeUT1: UT1TAI: International Atomic TimeGPS: Global Positioning System (GPS) timeTDB: 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/ ERFAdatfrom 1961-01-01: TAI - UTC drifts linearly and steps by fractions of a second (positive steps are labelled23:59:60.x). Before 1961, UTC is taken to equal TAI (unlike ERFA, which also models 1960).
Example
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:MMor±HH; hours 00-23, minutes 00-59) and is applied:"2024-01-04 13:14:12 +0100"is12: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_rfc3339orstrptimewhen 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 |
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].Tmay bet. 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),±HHMMor±HH(ISO 8601 forms, also accepted), with hours 00-23 and minutes 00-59. The offset is applied:2024-01-01T12:00:00+01:00is11: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
-0001or+10000, asto_rfc3339writes 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 |
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
-0044or+10000, asstrftimewrites 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 (
5is 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,±HHMMor±HH(exactly two digits per field, hours 00-23, minutes 00-59), orZ/zfor UTC.+HHMMmeans local time is ahead of UTC, so12:00:00+0100is11:00:00Z; the offset shifts the calendar label, so it is exact across a leap second - %% - a literal
%
- %Y - year: exactly four digits, or a sign and at least four
digits (ISO 8601 expanded years such as
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 |
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 |
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 |
OverflowError
|
If the result is beyond about ±292,000 years |
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 |
OverflowError
|
If the result is beyond about ±292,000 years |
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 |
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 |
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 |
OverflowError
|
If the result is beyond about ±292,000 years |
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 |
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
|
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 |
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. |
required |
scale
|
timescale
|
Time scale in which the components
are given, as for |
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 |
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 |
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
|
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.
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 |
True
|
Returns:
| Type | Description |
|---|---|
datetime
|
"datetime.datetime" object representing the same instant in time as the "satkit.time" object |
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 |
OverflowError
|
If the result is beyond about ±292,000 years |
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 |
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 |
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 |
__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 |
__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 |
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 |
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
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 |
OverflowError
|
if the difference is beyond about ±292,000 years |
Returns:
| Type | Description |
|---|---|
duration
|
Duration |
__init__(year, month, day, hour, min, sec, /, *, scale=timescale.UTC)
¶
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 timetime(string): parse a string, RFC 3339 first (e.g."2023-03-05T11:03:45.453Z"), then other common formatstime(t): the instant of anothersatkit.time, adatetime.datetimeor anumpy.datetime64time(year, month, day): midnight at the start of the daytime(year, month, day, hour, min, sec): all six components
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
string
|
String representation of time |
required | |
t
|
A |
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. |
required |
scale
|
timescale
|
Time scale in which the Gregorian components are
interpreted, default is satkit.timescale.UTC. Only for the
|
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
|
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 |
__add__(other)
¶
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a |
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 |
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 |
OverflowError
|
if |
Returns:
| Type | Description |
|---|---|
time
|
Time object representing the input number of days added to the current time |
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a |
OverflowError
|
if a result is beyond about ±292,000 years |
Returns:
| Type | Description |
|---|---|
NDArray[Any]
|
Object array of time objects, |
__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)
¶
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a |
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 |
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
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 |
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 |
OverflowError
|
if |
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 |
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 |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a |
OverflowError
|
if a result is beyond about ±292,000 years |
Returns:
| Type | Description |
|---|---|
NDArray[Any]
|
Object array of time objects, |
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, |
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
OverflowErrorwhen 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
|
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 |
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 |
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 |
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 |
OverflowError
|
If |
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 |
to_timedelta()
¶
__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 |
__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: |
required |
Returns:
| Type | Description |
|---|---|
duration
|
Duration object representing the input duration scaled by the input value |
Raises:
| Type | Description |
|---|---|
ValueError
|
if |
OverflowError
|
if the result is beyond about ±292,000 years |
__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 |
OverflowError
|
if the result is beyond about ±292,000 years |
__neg__()
¶
__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 |
__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
__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
__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
__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
__add__(other)
¶
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
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 |
__truediv__(other)
¶
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 |
ValueError
|
if |
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.
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 |
__floordiv__(other)
¶
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
|
|
Raises:
| Type | Description |
|---|---|
ZeroDivisionError
|
if |
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 |
Raises:
| Type | Description |
|---|---|
ZeroDivisionError
|
if |
ValueError
|
if |
OverflowError
|
if the result is beyond about ±292,000 years |
weekday
¶
Represent the day of the week
Values:
SundayMondayTuesdayWednesdayThursdayFridaySaturdayInvalid: placeholder that is not a day;time.weekdaynever 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)