ssb_timeseries.dates

Helper module for date and time utility functions.

Notable examples include converting between UTC and local time, standardised string formats for file names, and (planned for future use) intervals.

class Interval(f=None, t=None, **kwargs)

Bases: object

or a number of variations of named parameters: start/stop, begin/end, as_of, as_of_from/as_of_to, valid_from, valid_to - If only “as_of” is provided, start/stop are both set to this date. Interval.start defaults to datetime.min Interval.stop defaults to datetime.max

__init__(f=None, t=None, **kwargs)

Interval(date_from, date_to) or a number of variations of named parameters: start/stop, begin/end, as_of, as_of_from/as_of_to, valid_from, valid_to - If only “as_of” is provided, start/stop are both set to this date. Interval.start defaults to datetime.min Interval.stop defaults to datetime.max

Return type:

None

all()
includes(*args)
Parameters:

args (datetime | list[datetime])

date_local(some_date, **kwargs)

Convert date to Europe/Oslo timezone; ie shifting between CET and CEST.

If the date has no timezone information, the data is assumed to be in Oslo timezone.

The output will be rounded to the precision specified by kwarg ‘rounding’. Default precision ‘minute’ will be used if none is provided.

Return type:

datetime

Parameters:

some_date (datetime | str)

date_round(d, **kwargs)

Round date to specified by kwarg ‘rounding’ or default precision.

Rounding can take the values ‘none’, ‘day’, ‘d’, ‘hour’, ‘h’, ‘minute’, ‘min’, ‘m’, ‘second’, ‘sec’, or ‘s’.

Default precision ‘minute’ is used if none is provided.

Return type:

datetime

Parameters:

d (datetime)

date_utc(some_date, **kwargs)

Convert date to UTC.

If date has no timezone information, the data is assumed to be in CET.

The output will be rounded to the precision specified by kwarg ‘rounding’. Max precision ‘second’ will be used if none is provided.

Return type:

datetime

Parameters:

some_date (datetime | str | None)

ensure_datetime(some_date_representation, **kwargs)

Make sure that we are dealing with a datetime object, convert if possible.

If input is None or empty strings will be converted to now_utc().

Return type:

datetime

Parameters:

some_date_representation (Any)

ensure_tz_aware(some_date)

Make sure that our datetime object is timezone aware.

Assume CET if timezone information is missing.

Return type:

datetime

Parameters:

some_date (datetime)

is_tz_aware(d)
Return type:

bool

Parameters:

d (datetime)

is_tz_naive(d)
Return type:

bool

Parameters:

d (datetime)

now_cet(**kwargs)

Return now in CET.

Return type:

datetime

now_utc(**kwargs)

Return now in UTC.

Return type:

datetime

utc_iso(d, timespec='seconds')

Convert date to UTC and return as an ISO formatted string.

Return type:

str

Parameters:
  • d (Any)

  • timespec (str)

utc_iso_no_colon(d, timespec='seconds')

Convert date to UTC and return as an ISO formatted string without the colons.

Return type:

str

Parameters:
  • d (datetime)

  • timespec (str)