Skip to content

keplemon.time

Basic Usage

from keplemon.time import Epoch, TimeSpan
from keplemon.enums import TimeSystem

epoch = Epoch.from_iso("2025-04-02T04:42:42.123", TimeSystem.UTC)
span = TimeSpan.from_minutes(17.42)

new_epoch = epoch + span
time_components = new_epoch.to_time_components()

print("new_epoch.to_iso()")
print(f"Year: {time_components.year}")
print(f"Month: {time_components.month}")
print(f"Day: {time_components.day}")
print(f"Hour: {time_components.hour}")
print(f"Minute: {time_components.minute}")
print(f"Second: {time_components.second}")
2025-04-02T05:00:7.323
Year: 2025
Month: 4
Day: 2
Hour: 5
Minute: 0
Second: 7.323000056

time

Epoch

day_of_year instance-attribute

Decimal day of the year (1-365.999...)

days_since_1950 instance-attribute

Core floating epoch representation used by the SAAL binaries.

gst instance-attribute

Greenwich Sidereal Time in radians

time_system instance-attribute

from_datetime(dt) classmethod

Parameters:

Name Type Description Default
dt datetime

Aware or naive datetime object (assumed to be UTC if naive)

required

from_days_since_1950(days, time_system) classmethod

Parameters:

Name Type Description Default
days float

Days since 1 Jan 1956

required
time_system TimeSystem

System used to calculate the number of days since 1 Jan 1956

required

from_dtg(dtg, time_system) classmethod

Create an epoch from a standard SAAL DTG format.

Note

DTG formats include:

  • DTG 20: YYYY/DDD HHMM SS.SSS
  • DTG 19: YYYYMonDDHHMMSS.SSS
  • DTG 17: YYYY/DDD.DDDDDDDD
  • DTG 15: YYDDDHHMMSS.SSS

Parameters:

Name Type Description Default
dtg str

DTG formatted string (YYYY/DDD hhmm ss.sss)

required
time_system TimeSystem

System used to calculate the epoch

required

from_iso(iso_str, time_system) classmethod

Parameters:

Name Type Description Default
iso_str str

ISO 8601 formatted string (YYYY-MM-DDThh:mm:ss.sss)

required
time_system TimeSystem

System used to calculate the epoch

required

from_time_components(components, time_system) classmethod

Parameters:

Name Type Description Default
components TimeComponents

Epoch represented as individual components

required
time_system TimeSystem

System used to calculate the epoch

required

now() classmethod

Returns:

Type Description
Epoch

Current epoch in UTC time system

to_datetime()

Returns:

Type Description
datetime

Aware datetime object in UTC time system

to_dtg_15()

Returns:

Type Description
str

Epoch in DTG 15 format (YYDDDHHMMSS.SSS)

to_dtg_17()

Returns:

Type Description
str

Epoch in DTG 17 format (YYYY/DDD.DDDDDDDD)

to_dtg_19()

Returns:

Type Description
str

Epoch in DTG 19 format (YYYYMonDDHHMMSS.SSS)

to_dtg_20()

Returns:

Type Description
str

Epoch in DTG 20 format (YYYY/DDD HHMM SS.SSS)

to_fk4_greenwich_angle()

Returns:

Type Description
float

Greenwich angle in radians using FK4 theory

to_fk5_greenwich_angle()

Returns:

Type Description
float

Greenwich angle in radians using FK5 theory

to_iso()

Returns:

Type Description
str

Epoch in ISO 8601 format (YYYY-MM-DDThh:mm:ss.sss)

to_system(time_system)

Convert the epoch to a different time system.

Parameters:

Name Type Description Default
time_system TimeSystem

Desired ouput system

required

to_time_components()

Returns:

Type Description
TimeComponents

Epoch as individual components

TimeComponents

day instance-attribute

hour instance-attribute

minute instance-attribute

month instance-attribute

second instance-attribute

year instance-attribute

__init__(year, month, day, hour, minute, second)

Initialize TimeComponents with the given year, month, day, hour, minute, and second.

Warning

It is the user's responsibility to input valid month/day combinations and time values. This class does not perform validation.

Parameters:

Name Type Description Default
year int

Year (e.g., 2023)

required
month int

Month (1-12)

required
day int

Day (1-31)

required
hour int

Hour (0-23)

required
minute int

Minute (0-59)

required
second float

Second (0.0-59.999...)

required

from_iso(iso_str) classmethod

Parameters:

Name Type Description Default
iso_str str

ISO 8601 formatted string (YYYY-MM-DDThh:mm:ss.sss)

required

to_iso()

Returns:

Type Description
str

Epoch in ISO 8601 format (YYYY-MM-DDThh:mm:ss.sss)

TimeSpan

from_days(days) classmethod

Parameters:

Name Type Description Default
days float

Total duration in days

required

from_hours(hours) classmethod

Parameters:

Name Type Description Default
hours float

Total duration in hours

required

from_minutes(minutes) classmethod

Parameters:

Name Type Description Default
minutes float

Total duration in minutes

required

from_seconds(seconds) classmethod

Parameters:

Name Type Description Default
seconds float

Total duration in seconds

required

in_days()

Returns:

Type Description
float

Total duration in days

in_hours()

Returns:

Type Description
float

Total duration in hours

in_minutes()

Returns:

Type Description
float

Total duration in minutes

in_seconds()

Returns:

Type Description
float

Total duration in seconds

request_time_constants_update(output_path)

Request time constants and EOP data from USNO and save to the specified path.

Parameters:

Name Type Description Default
output_path Union[str, Path]

Path where the SAAL-formatted time constants will be written

required