Skip to content

API

PreciseDateTime

Precise date-time object with picosecond timing accuracy.

Attributes

__all__ module-attribute

Python
__all__ = ['PreciseDateTime']

Classes

PreciseDateTime

Precise Date Time format specification.

Field Value / Format Description
Precision 1e-12 s Picosecond precision
Standard format "DD-MMM-YYYY hh:mm:ss.pppppppppppp" Default string representation
Standard reference date PRECISEDATETIME_REFERENCE_TIME Reference epoch
DD — Day
MMM JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC Month (three-letter uppercase abbreviation)
YYYY — Year (4 digits)
hh 00-23 Hours (24-hour format)
mm 00-59 Minutes
ss 00-59 Seconds
pppppppppppp 12 digits Picoseconds

Attributes

__hash__ class-attribute instance-attribute
Python
__hash__ = None
__radd__ class-attribute instance-attribute
Python
__radd__ = __add__
year property
Python
year: int

Year associated to the current time point.

month property
Python
month: int

Month associated to the current time point.

day_of_the_month property
Python
day_of_the_month: int

Day of the month associated to the current time point.

hour_of_day property
Python
hour_of_day: int

Hour of the day associated to the current time point.

minute_of_hour property
Python
minute_of_hour: int

Minute of the hour associated to the current time point.

second_of_minute property
Python
second_of_minute: int

Second of the minute associated to the current time point.

picosecond_of_second property
Python
picosecond_of_second: float

Picosecond of the second associated to the current time point.

fraction_of_day property
Python
fraction_of_day: float

Fraction of the day associated to the current time point.

day_of_the_year property
Python
day_of_the_year: int

Day from the first day of the year associated to the current time point.

sec85 property
Python
sec85: float

Time distance in seconds from PRECISEDATETIME_1985 to the current time point.

Methods:

__init__
Python
__init__(seconds: float = 0.0, picoseconds: float = 0.0) -> None

Initialize the PreciseDateTime object with the specified time point.

Parameters:

Name Type Description Default
seconds float

number of seconds since reference date, by default 0.0

0.0
picoseconds float

number of picoseconds since reference date, by default 0.0

0.0

Raises:

Type Description
ValueError

Raised when negative values are passed as arguments

__iadd__
Python
__iadd__(seconds: float) -> Self

Add the input seconds to the current time point.

Parameters:

Name Type Description Default
seconds float

number of seconds to add to the current time point

required

Returns:

Type Description
PreciseDateTime

self

__isub__
Python
__isub__(seconds: float) -> Self

Subtract the input seconds from the current time point.

Parameters:

Name Type Description Default
seconds float

number of seconds to subtract from the current time point

required

Returns:

Type Description
PreciseDateTime

self

__add__
Python
__add__(seconds: float) -> PreciseDateTime

Return the sum between the current time point and the specified input seconds.

Parameters:

Name Type Description Default
seconds float

number of seconds to add to the current time point

required

Returns:

Type Description
PreciseDateTime

a new PreciseDateTime object initialized to the resulting time point

__sub__
Python
__sub__(other: float) -> PreciseDateTime
Python
__sub__(other: PreciseDateTime) -> float
Python
__sub__(other: float | PreciseDateTime) -> float | PreciseDateTime

Return the difference between the current time point and a float or a PreciseDateTime object.

Parameters:

Name Type Description Default
other float | PreciseDateTime

number of seconds or PreciseDateTime object to subtract from the current time point

required

Returns:

Type Description
float | PreciseDateTime:

if the input parameter is a PreciseDateTime object, the difference in seconds between the two time points; otherwise, a new PreciseDateTime object initialized to the resulting time point

__repr__
Python
__repr__() -> str

Return a string representation of the current time point.

__eq__
Python
__eq__(other: object) -> bool

Compare the current time point with another PreciseDateTime object for equality.

__lt__
Python
__lt__(other: object) -> bool

Compare the current time point with another PreciseDateTime object.

get_precision classmethod
Python
get_precision() -> float

Date-time representation precision.

Returns:

Type Description
float

precision of the date-time representation in seconds

get_reference_datetime classmethod
Python
get_reference_datetime() -> datetime.datetime

Get reference date-time.

Returns:

Type Description
datetime

reference date-time as a datetime object

now classmethod
Python
now() -> PreciseDateTime

Create an object with the current time (local timezone).

from_sec85 classmethod
Python
from_sec85(seconds: float) -> PreciseDateTime

Create an object with the time point defined by adding the specified input seconds to PRECISEDATETIME_1985.

Parameters:

Name Type Description Default
seconds float

number of seconds from PRECISEDATETIME_1985

required

Returns:

Type Description
PreciseDateTime

the time point

from_utc_string classmethod
Python
from_utc_string(utc_str: str) -> PreciseDateTime

Create an object with the time point specified by the input UTC string.

Parameters:

Name Type Description Default
utc_str str

UTC string

required

Returns:

Type Description
PreciseDateTime

the time point

from_numeric_datetime classmethod
Python
from_numeric_datetime(year: int, month: int = 1, day: int = 1, hours: int = 0, minutes: int = 0, seconds: int = 0, picoseconds: float = 0.0) -> PreciseDateTime

Create an object with the time point specified by the input date and time parameters.

Parameters:

Name Type Description Default
year int

year

required
month int

from 1 to 12, by default 1

1
day int

from 1 to 28-31 (depending on month), by default 1

1
hours int

from 0 to 23, by default 0

0
minutes int

from 0 to 59, by default 0

0
seconds int

from 0 to 59, by default 0

0
picoseconds float

non-negative and less than 1e12, by default 0.0

0.0

Returns:

Type Description
PreciseDateTime

the time point

Raises:

Type Description
ValueError

in case of invalid picoseconds

fromisoformat classmethod
Python
fromisoformat(datetime_string: str, sep: str = 'T') -> PreciseDateTime

Create an object with the time specified by the input ISO string.

Parameters:

Name Type Description Default
datetime_string str

time specified as ISO string

required
sep str

separator between date and time, by default "T"

'T'

Returns:

Type Description
PreciseDateTime

the time point

Raises:

Type Description
ValueError

in case of an invalid input datetime string

isoformat
Python
isoformat(sep: str = 'T', timespec: str = 'auto') -> str

ISO formatting of the time point.

Parameters:

Name Type Description Default
sep str

separator between date and time, by default "T"

'T'
timespec str

number of extra terms to include in the string, by default auto.

Valid options are: auto, hours, minutes, seconds, milliseconds, microseconds, nanoseconds and picoseconds.

'auto'

Returns:

Type Description
str

time formatted according to ISO

Timing conversions

Timing conversion utilities.

Attributes

__all__ module-attribute

Python
__all__ = ['date_to_gps_week']

Classes

Functions:

date_to_gps_week

Python
date_to_gps_week(date: PreciseDateTime | datetime) -> tuple[int, int]

Convert input date to GPS week.

GPS weeks are counted since 06-January-1980.

Parameters:

Name Type Description Default
date PreciseDateTime | datetime

date to be converted to GPS week, in PreciseDateTime or datetime format

required

Returns:

Type Description
int

GPS week

int

GPS day of the week

Raises:

Type Description
ValueError

if input date is before 06-January-1980

precise_datetime_to_numpy

Python
precise_datetime_to_numpy(times: PreciseDateTime | ndarray) -> np.datetime64 | np.ndarray

Convert PreciseDateTime to numpy.datetime64 data type truncated to nanoseconds precision.

Parameters:

Name Type Description Default
times PreciseDateTime | ndarray

times to be converted from PreciseDateTime format to numpy.datetime64[ns]

required

Returns:

Type Description
datetime64 | ndarray

numpy.datetime64[ns] at nanoseconds precision corresponding to the input times