asi_core.utils.datetime_handling

Functions

get_ETC_GMT_timezone([desired_timezone])

Convert the given Etc/GMT timezone into a pytz timezone object.

parse_datetime(dt_string[, datetime_format, raise_on_fail])

Extract timestamp from string into datetime object.

get_temporal_resolution_from_timeseries(data)

Get temporal resolution from a pandas DataFrame with a DatetimeIndex.

timezone_ISO8601_to_pytz_posix(tz)

Convert from ISO 8601 to posix convention (ISO 8601: Positive east of Greenwich)

Module Contents

asi_core.utils.datetime_handling.get_ETC_GMT_timezone(desired_timezone='GMT')

Convert the given Etc/GMT timezone into a pytz timezone object.

Example: UTC+2: get_ETC_GMT_timezone(‘GMT+2’) returns pytz timezone object for “Etc/GMT-2”

Parameters:

desired_timezone – (str) A string specifying the desired GMT timezone. It should be in the format ‘GMT+1’ (in the case of UTC+1). If a ‘+’ sign is used, it will be replaced with ‘-’ to follow the Etc/GMT convention (https://en.wikipedia.org/wiki/Tz_database#Area).

Returns:

(pytz.timezone), Etc/GMT timezone

asi_core.utils.datetime_handling.parse_datetime(dt_string, datetime_format='%Y%m%d%H%M%S', raise_on_fail=False)

Extract timestamp from string into datetime object.

Parameters:
  • dt_string (str) – Timestamp string

  • datetime_format (str) – Datetime format template with the following placeholders: %Y year, %m month, %d day, %H hour, %M minute, %S second. Default is “%Y%m%d%H%M%S”.

  • raise_on_fail (bool) – Flag to decide whether to raise an error or return None if no timestamp could be extracted. Default is False.

Returns:

Timestamp from given string.

Return type:

datetime.datetime

asi_core.utils.datetime_handling.get_temporal_resolution_from_timeseries(data)

Get temporal resolution from a pandas DataFrame with a DatetimeIndex. Resolution is rounded to seconds

Parameters:

data – (DataFrame) DataFrame with datetime index

Returns:

(Timedelta) DataFrame time resolution

asi_core.utils.datetime_handling.timezone_ISO8601_to_pytz_posix(tz)

Convert from ISO 8601 to posix convention (ISO 8601: Positive east of Greenwich)

Parameters:

tz – (str) A string specifying the desired GMT timezone. It should be in the format ‘GMT+1’ (in the case of UTC+1). If a ‘+’ sign is used, it will be replaced with ‘-’ to follow the Etc/GMT convention (https://en.wikipedia.org/wiki/Tz_database#Area).

Returns:

(str), Etc/GMT timezone