lsst.sims.ocs.kernel.time_handler module¶
-
class
lsst.sims.ocs.kernel.time_handler.
TimeHandler
(initial_date)[source]¶ Bases:
future.types.newobject.newobject
Keep track of simulation time information.
-
_unix_start
¶ datetime.datetime – Holder for the start of the UNIX epoch
-
initial_dt
¶ datetime.datetime – The date/time of the simulation start.
-
current_dt
¶ datetime.datetime – The current simulation date/time.
Initialize the class.
Parameters: initial_date (str) – The inital date in the format of YYYY-MM-DD. -
future_datetime
(time_increment, time_units, timestamp=None)[source]¶ 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_increment (float) – The increment to adjust the current time.
- time_units (str) – The time unit for the increment value.
- timestamp (float, 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)[source]¶ 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_increment (float) – The increment to adjust the current time.
- time_units (str) – The time unit for the increment value.
- timestamp (float, optional) – An alternative timestamp to apply the time increment to.
Returns: float – The future UNIX timestamp.
-
future_timestring
(time_increment, time_units, timestamp=None)[source]¶ 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_increment (float) – The increment to adjust the current time.
- time_units (str) – The time unit for the increment value.
- timestamp (float, optional) – An alternative timestamp to apply the time increment to.
Returns: str – The future date/time in ISO-8601.
-
has_time_elapsed
(time_span)[source]¶ Return a boolean 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_span (float) – 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)[source]¶ 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: timestamp (float) – A UNIX timestamp Returns: float – The elapsed time (seconds) between the given
-
time_since_given_datetime
(given_datetime, reverse=False)[source]¶ 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_datetime (datetime) – The given timestamp.
- reverse (bool, 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)[source]¶ Update the currently held timestamp.
This function updates the currently held time with the given increment and corresponding units.
Parameters: - time_increment (float) – The increment to adjust the current time.
- time_units (str) – The time unit for the increment value.
-
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.
-