time_format_datetime()

def time_format_datetime(unix_seconds, format_string) -> string

Formats a Unix timestamp as a human-readable datetime string.

Converts a Unix timestamp (seconds since epoch) into a formatted date/time string using strftime format codes. The timestamp is interpreted as UTC.

Raises: Error: If the timestamp is invalid or formatting fails

Args

  • unix_seconds: int: Unix timestamp in seconds (as an integer)
  • format_string: string: strftime format string (e.g., “%Y-%m-%d %H:%M:%S”)

Returns

str: Formatted datetime string

time_monotonic()

def time_monotonic() -> int

Gets process-local monotonic time in milliseconds.

Returns elapsed milliseconds since the first call to time_monotonic() (effectively process start for most scripts). This clock is monotonic, meaning it always moves forward and is not affected by system clock adjustments. Ideal for measuring elapsed time and benchmarking.

Returns

int: Milliseconds elapsed since the first call to time_monotonic()

time_now()

def time_now() -> float

Gets the current time in seconds since the Unix epoch (UTC).

Returns the current moment in time as a floating-point number of seconds since January 1, 1970, 00:00:00 UTC. This includes fractional seconds (nanosecond precision).

Returns

float: Current Unix timestamp with nanosecond precision

time_now_iso8601()

def time_now_iso8601() -> string

Returns the current UTC time as an ISO8601 / RFC3339 formatted string.

Returns the current moment formatted as a standard ISO8601 string, which is widely used in APIs and logging systems.

Returns

str: ISO8601 formatted timestamp (e.g., “2024-01-15T10:30:45.123456Z”)

time_parse_datetime()

def time_parse_datetime(datetime_string, format_string) -> int

Parses a datetime string and returns the Unix timestamp.

Converts a formatted datetime string into a Unix timestamp (seconds since epoch). If no timezone is specified in the string, UTC is assumed.

Raises: Error: If the string cannot be parsed with the given format

Args

  • datetime_string: string: The datetime string to parse
  • format_string: string: strftime format string matching the input (e.g., “%Y-%m-%d %H:%M:%S”)

Returns

int: Unix timestamp in seconds

time_sleep()

def time_sleep(seconds)

Pauses execution for the specified number of seconds.

Suspends the current thread for the given duration. Supports fractional seconds for sub-second delays (e.g., 0.5 for 500 milliseconds).

Args

  • seconds: float: Number of seconds to sleep. Can be fractional (e.g., 1.5)

time_sleep_milliseconds()

def time_sleep_milliseconds(milliseconds)

Pauses execution for the specified number of milliseconds.

Suspends the current thread for the given number of milliseconds. More precise than time_sleep for short delays.

Args

  • milliseconds: int: Number of milliseconds to sleep

time_sleep_seconds()

def time_sleep_seconds(seconds)

Pauses execution for the specified number of whole seconds.

Suspends the current thread for an integer number of seconds. Use this for longer delays where sub-second precision is not needed.

Args

  • seconds: int: Number of whole seconds to sleep

time_timer_elapsed_ms()

def time_timer_elapsed_ms(timer_id) -> int

Returns the elapsed milliseconds for a running timer.

Queries how much time has passed since the timer was started or reset. The timer continues running and can be queried multiple times.

Raises: Error: If the timer handle is invalid

Args

  • timer_id: int: Timer handle returned from time_timer_start()

Returns

int: Milliseconds elapsed since timer creation/reset

time_timer_elapsed_ns()

def time_timer_elapsed_ns(timer_id) -> int

Returns the elapsed nanoseconds for a running timer.

Queries elapsed time in nanoseconds since timer creation/reset. Use when you need nanosecond-precision timing for benchmarking.

Raises: Error: If the timer handle is invalid

Args

  • timer_id: int: Timer handle returned from time_timer_start()

Returns

int: Nanoseconds elapsed since timer creation/reset

time_timer_reset()

def time_timer_reset(timer_id)

Resets a timer to zero without destroying the timer handle.

Restarts the timer measurement from the current moment, clearing all previously elapsed time. The timer handle remains valid and can continue to be used.

Raises: Error: If the timer handle is invalid

Args

  • timer_id: int: Timer handle returned from time_timer_start()

time_timer_start()

def time_timer_start() -> int

Creates and starts a new timer for measuring elapsed time.

Returns a timer handle that can be used with other timer functions to measure how much time has passed since the timer was created.

Returns

int: Timer handle (unique identifier for this timer)

time_timer_stop()

def time_timer_stop(timer_id)

Stops and removes a timer from the registry.

Cleans up a timer handle, freeing its resources. After calling this, the timer handle can no longer be used. Call this when you’re done measuring to prevent resource leaks.

Raises: Error: If the timer handle is invalid or already stopped

Args

  • timer_id: int: Timer handle returned from time_timer_start()

time_unix_milliseconds()

def time_unix_milliseconds() -> int

Gets the current Unix timestamp in milliseconds.

Returns the number of milliseconds elapsed since the Unix epoch. Useful for timing intervals with millisecond precision without dealing with floating-point numbers.

Returns

int: Current Unix timestamp in milliseconds

time_unix_seconds()

def time_unix_seconds() -> int

Gets the current Unix timestamp in whole seconds.

Returns the number of seconds elapsed since the Unix epoch (January 1, 1970). This is useful for simple timestamp operations where sub-second precision is not needed.

Returns

int: Current Unix timestamp in seconds