nexusLIMS.utils.time#

Time and date utilities for NexusLIMS.

Module Contents#

Functions#

get_timespan_overlap

Find the amount of overlap between two time spans.

has_delay_passed

Check if the current time is greater than the configured delay.

current_system_tz_name

Get the system’s timezone name.

current_system_tz

Get the system’s timezone as a pytz timezone object.

Data#

API#

nexusLIMS.utils.time.sleep#
nexusLIMS.utils.time.get_timespan_overlap(range_1: Tuple[datetime, datetime], range_2: Tuple[datetime, datetime]) timedelta[source]#

Find the amount of overlap between two time spans.

Adapted from https://stackoverflow.com/a/9044111.

Parameters:
  • range_1 – Tuple of length 2 of datetime objects: first is the start of the time range and the second is the end of the time range

  • range_2 – Tuple of length 2 of datetime objects: first is the start of the time range and the second is the end of the time range

Returns:

The amount of overlap between the time ranges

Return type:

timedelta

nexusLIMS.utils.time.has_delay_passed(date: datetime) bool[source]#

Check if the current time is greater than the configured delay.

Check if the current time is greater than the configured (or default) record building delay configured in the NX_FILE_DELAY_DAYS environment variable. If the date given is timezone-aware, the current time in that timezone will be compared.

Parameters:

date – The datetime to check; can be either timezone aware or naive

Returns:

Whether the current time is greater than the given date plus the configurable delay.

Return type:

bool

nexusLIMS.utils.time.current_system_tz_name() str[source]#

Get the system’s timezone name.

Returns the IANA timezone database name for the system’s current timezone (e.g., ‘America/New_York’), never a simple UTC offset.

Returns:

The IANA timezone name (e.g., ‘America/New_York’, ‘Europe/London’)

Return type:

str

Examples:

>>> current_system_tz_name()
'America/New_York'
nexusLIMS.utils.time.current_system_tz() DstTzInfo[source]#

Get the system’s timezone as a pytz timezone object.

Returns the system’s current timezone as a pytz timezone object with a named timezone (e.g., ‘America/New_York’), never a simple UTC offset.

Returns:

A pytz timezone object representing the system’s timezone

Return type:

DstTzInfo

Examples:

>>> tz = get_system_tz()
>>> tz.zone
'America/New_York'