TimeHandler¶
- class rubin_sim.utils.TimeHandler(initial_date)¶
Bases:
object
Keep track of simulation time information.
This is a class tied to SOCS/Scheduler (OpSim). Its properties will be reevaluated in the future and this class may disappear.
- Attributes:
- _unix_startdatetime.datetime
Holder for the start of the UNIX epoch
- initial_dtdatetime.datetime
The date/time of the simulation start.
- current_dtdatetime.datetime
The current simulation date/time.
Attributes Summary
float: Return the UNIX timestamp of midnight for the current date.
float: Return the UNIX timestamp for the current date/time.
str: Return the ISO-8601 representation of the current date/time.
float: Return the UNIX timestamp for the initial date/time.
float: Return the UNIX timestamp of midnight for the next day after current date.
float: The number of seconds since the start date.
Methods Summary
future_datetime
(time_increment, time_units)Return a future datetime object.
future_timestamp
(time_increment, time_units)Return the UNIX timestamp for the future date/time.
future_timestring
(time_increment, time_units)Return the ISO-8601 representation of the future date/time.
has_time_elapsed
(time_span)Return a
bool
determining if the time span has elapsed.time_since_given
(timestamp)Return the elapsed time (seconds).
time_since_given_datetime
(given_datetime[, ...])Return the elapsed time (seconds).
update_time
(time_increment, time_units)Update the currently held timestamp.
Attributes Documentation
- current_midnight_timestamp¶
float: Return the UNIX timestamp of midnight for the current date.
- current_timestamp¶
float: Return the UNIX timestamp for the current date/time.
- current_timestring¶
str: Return the ISO-8601 representation of the current date/time.
- initial_timestamp¶
float: Return the UNIX timestamp for the initial date/time.
- next_midnight_timestamp¶
float: Return the UNIX timestamp of midnight for the next day after current date.
- time_since_start¶
float: The number of seconds since the start date.
Methods Documentation
- future_datetime(time_increment, time_units, timestamp=None)¶
Return a future datetime object.
This function adds the requested time increment to the current date/time to get a future date/time and returns a datetime object. An alternative timestamp can be supplied and the time increment will be applied to that instead. This function does not update the internal timestamp.
- Parameters:
- time_incrementfloat
The increment to adjust the current time.
- time_unitsstr
The time unit for the increment value.
- timestampfloat, optional
An alternative timestamp to apply the time increment to.
- Returns:
- datetime.datetime
The datetime object for the future date/time.
- future_timestamp(time_increment, time_units, timestamp=None)¶
Return the UNIX timestamp for the future date/time.
This function adds the requested time increment to the current date/time to get a future date/time and returns the UNIX timestamp for that date/time. It does not update the internal timestamp.
- Parameters:
- time_incrementfloat
The increment to adjust the current time.
- time_unitsstr
The time unit for the increment value.
- timestampfloat, optional
An alternative timestamp to apply the time increment to.
- Returns:
- float
The future UNIX timestamp.
- future_timestring(time_increment, time_units, timestamp=None)¶
Return the ISO-8601 representation of the future date/time.
This function adds the requested time increment to the current date/time to get a future date/time and returns the ISO-8601 formatted string for that date/time. It does not update the internal timestamp.
- Parameters:
- time_incrementfloat
The increment to adjust the current time.
- time_unitsstr
The time unit for the increment value.
- timestampfloat, optional
An alternative timestamp to apply the time increment to.
- Returns:
- str
The future date/time in ISO-8601.
- has_time_elapsed(time_span)¶
Return a
bool
determining if the time span has elapsed.This function looks to see if the time elapsed (current_time - initial_time) in units of seconds is greater or less than the requested time span. It will return true if the time span is greater than or equal the elapsed time and false if less than the elapsed time.
- Parameters:
- time_spanfloat
The requested time span in seconds.
- Returns:
- bool
True if the time elapsed is greater or False if less than the time span.
- time_since_given(timestamp)¶
Return the elapsed time (seconds).
This function takes the given timestamp and calculates the elapsed time in seconds between it and the initial timestamp in the handler.
- Parameters:
- timestampfloat
A UNIX timestamp
- Returns:
- float
The elapsed time (seconds) between the given
- time_since_given_datetime(given_datetime, reverse=False)¶
Return the elapsed time (seconds).
This function takes a given datetime object and calculates the elapsed time in seconds between it and the initial timestamp in the handler. If the given datetime is prior to the initial timestamp in the handler, use the reverse flag.
- Parameters:
- given_datetimedatetime
The given timestamp.
- reversebool, optional
Flag to make the difference in reverse. Default is False.
- Returns:
- float
The elapsed time (seconds) between the given timestamp and the initial timestamp
- update_time(time_increment, time_units)¶
Update the currently held timestamp.
This function updates the currently held time with the given increment and corresponding units.
- Parameters:
- time_incrementfloat
The increment to adjust the current time.
- time_unitsstr
The time unit for the increment value.