Logo
Telescience Resource Kit
TReK Python  5.4.0 ART
TrekTime Class Reference

This class holds a time value represented as seconds from the system epoch. More...

Public Member Functions

Initialize / Finalize

Functions handling class initialization and finalization.

def TrekTime ( Optional[TrekTime] trek_time=None, Optional[c_void_p] native_ptr=None -> def ) -> def 
 Class initializer. More...
 
Get Time

Functions to return time.

def __str__ ( -> str ) -> def 
 Returns get_time_string(), fractional, not file friendly.
 
def get_delta_time (delta_from: TrekTime -> float ) -> def 
 Gets the difference between two times. More...
 
def get_time ( -> tuple[int, int] ) -> def 
 Gets the time relative the system epoch. More...
 
def get_time_components ( -> TrekTimeComponents ) -> def 
 Gets the complete time value in components. More...
 
def get_time_float ( -> float ) -> def 
 Gets time relative the system epoch as a 64-bit floating point. More...
 
def get_time_string (fractional: bool=True, file_friendly: bool=False -> str ) -> def 
 Gets the time as string. More...
 
def get_iso_time_string ( -> str ) -> def 
 Gets an ISO 8601 formatted time string.
 
def get_seconds ( -> int ) -> def 
 Returns the current number of seconds since the epoch. More...
 
def get_subseconds ( -> int ) -> def 
 Returns the current number of seconds since the epoch. More...
 
def get_subseconds_per_second ( -> int ) -> def 
 Returns the current number of subseconds per second. More...
 
Set Time

Functions to set time.

def copy (copy_from: TrekTime -> None ) -> def 
 Copies the content values of the provided 'copy_from' TrekTime into the callings' TrekTime. More...
 
def shift_time (shift_amount: float -> None ) -> def 
 Shifts the time. More...
 
def set_time ( -> None ) -> def 
 Sets the time to the current system time. More...
 
def set_time_by_secs_subs (secs: int, subsecs: int=0 -> None ) -> def 
 Sets the time relative the system epoch based on the input. More...
 
def set_iso_time_by_string (timestr: str -> None ) -> def 
 Sets the time with an ISO 8601 formatted time string. More...
 
def set_time_by_string (timestr: str -> None ) -> def 
 Sets the time based on the input string. More...
 
def set_time_by_float (time_float: float -> None ) -> def 
 Sets the time relative the system epoch based on the input. More...
 
def set_subsec_per_second (subsecsper: int -> None ) -> def 
 Set the number of subseconds per second. More...
 

Detailed Description

This class holds a time value represented as seconds from the system epoch.

The time may also have an optional fractional second (subsecond) value. The number of subseconds allowed is enforced by the maximum subseconds per second value. The default number of subseconds per second is 1,000,000 (microseconds).

Note
Windows systems can use this class to represent times until 2100-01-01. However, Linux systems can only represent time until 2038-01-19 03:14:07.

Constructor & Destructor Documentation

◆ TrekTime()

(trek_time : Optional[TrekTime]  
native_ptr : Optional[c_void_p]  
) -> def

Class initializer.

TrekTime creation:

my_time = TrekTime()
Parameters
[in]trek_time(Optional) TrekTime to copy.
[in]native_ptrInternal parameter, do not provide.

Member Function Documentation

◆ copy()

(copy_from : TrekTime ) -> None

Copies the content values of the provided 'copy_from' TrekTime into the callings' TrekTime.

Parameters
[in]copy_fromTrekTime from which to copy.

◆ get_delta_time()

(delta_from : TrekTime ) -> float

Gets the difference between two times.

Calculates a 64-bit float point difference in seconds. Times are not required to have same subsecond resolution.

Parameters
[in]delta_fromTrekTime to delta with.
Returns
Difference in seconds.

◆ get_seconds()

() -> int

Returns the current number of seconds since the epoch.

Returns
Number of seconds since epoch.

◆ get_subseconds()

() -> int

Returns the current number of seconds since the epoch.

Returns
Number of seconds since epoch.

◆ get_subseconds_per_second()

() -> int

Returns the current number of subseconds per second.

Returns
Number of subseconds per second.

◆ get_time()

() -> tuple[int, int]

Gets the time relative the system epoch.

Returns
[seconds, subseconds]

◆ get_time_components()

Gets the complete time value in components.

Returns
trek.trektime.TrekTimeComponents

◆ get_time_float()

() -> float

Gets time relative the system epoch as a 64-bit floating point.

Returns
The time as seconds since epoch.

◆ get_time_string()

(fractional : bool  
file_friendly : bool  
) -> str

Gets the time as string.

Parameters
[in]fractionalInclude subseconds.
[in]file_friendlyUses '-' instead of ':' and '' for formatting.

◆ set_iso_time_by_string()

(timestr : str ) -> None

Sets the time with an ISO 8601 formatted time string.

Parameters
[in]timestrThe ISO 8601 formatted time string (e.g. 2024-03-08T09:12:34.0123Z).
Exceptions
TrekError15086 - TREK_DATA_TIME_LENGTH_ERROR,

15087 - TREK_DATA_TIME_STRING_FORMAT_ERROR,

15088 - TREK_DATA_TIME_TOO_SOON,

15089 - TREK_DATA_ILLEGAL_MONTH,

15090 - TREK_DATA_ILLEGAL_DAY,

15091 - TREK_DATA_ILLEGAL_HOURS,

15092 - TREK_DATA_ILLEGAL_MINUTES,

15093 - TREK_DATA_ILLEGAL_SECONDS

◆ set_subsec_per_second()

(subsecsper : int ) -> None

Set the number of subseconds per second.

Also resets the current subseconds to zero.

Parameters
[in]subsecsperThe number of subseconds per second.

◆ set_time()

() -> None

Sets the time to the current system time.

If the subseconds per second are allowed (see set_subsec_per_second), fractional seconds will be set as well.

◆ set_time_by_float()

(time_float : float ) -> None

Sets the time relative the system epoch based on the input.

Parameters
[in]time_floatThe new time in seconds from a 64-bit floating point.
Exceptions
TrekError15085 - TREK_DATA_NEG_TIME_NOT_ALLOWED

◆ set_time_by_secs_subs()

(secs : int 
subsecs : int  
) -> None

Sets the time relative the system epoch based on the input.

Parameters
[in]secsThe new seconds (>=0) since the epoch.
[in]subsecsThe new subseconds (>=0) of seconds.
Exceptions
TrekError15084 - TREK_DATA_FRACTIONAL_TIME_VALUE_ERROR

◆ set_time_by_string()

(timestr : str ) -> None

Sets the time based on the input string.

The format of the string is:

YYYY-MM-DD hh:mm:ss(.fffff)
  • YYYY is the year and between 1970 and 2099 inclusive.
  • MM is the month between 01 and 12 inclusive
  • DD is the day between 01 and 31 inclusive
  • hh is the hours between 00 and 23 inclusive
  • mm is the minutes between 00 and 59 inclusive
  • ss is the seconds between 00 and 59 inclusive
  • (.fffff) is the optional fractional seconds without the parentheses.
Parameters
[in]timestrThe new time.
Exceptions
TrekError15086 - TREK_DATA_TIME_LENGTH_ERROR,

15087 - TREK_DATA_TIME_STRING_FORMAT_ERROR,

15088 - TREK_DATA_TIME_TOO_SOON,

15089 - TREK_DATA_ILLEGAL_MONTH,

15090 - TREK_DATA_ILLEGAL_DAY,

15091 - TREK_DATA_ILLEGAL_HOURS,

15092 - TREK_DATA_ILLEGAL_MINUTES,

15093 - TREK_DATA_ILLEGAL_SECONDS

◆ shift_time()

(shift_amount : float ) -> None

Shifts the time.

Adds the input time to the current value stored in class.

Parameters
[in]shift_amountTime in seconds to shift.
Exceptions
TrekError15085 - TREK_DATA_NEG_TIME_NOT_ALLOWED