ssb_befolkning_fagfunksjoner.date_utils package

ssb_befolkning_fagfunksjoner.date_utils.dates module

get_last_day_of_month(input_date)

Given a date object, return a new date object representing the last day of that month.

Return type:

date

Parameters:

input_date (date)

get_last_day_of_next_month(input_date)

Given a date object, return a new date object representing the last day of the following month.

Return type:

date

Parameters:

input_date (date)

ssb_befolkning_fagfunksjoner.date_utils.event_params module

class EventParams(year=None, period_type=None, period_number=None, specify_wait_period=False)

Bases: object

Class for handling event periods.

  • Prompts and validates event periods

  • Creates period labels (Dapla-standard)

  • Computes calendar windows for period

  • Exposes event parameters for parameterising SQL queries

Parameters:
  • year (int | None)

  • period_type (str | None)

  • period_number (int | None)

  • specify_wait_period (bool)

VALID_PERIOD_TYPES: tuple[PeriodType, ...] = ('year', 'halfyear', 'quarter', 'month', 'week')
property etterslep_label: str

‘1m0d’.

Defaults to ‘1m0d’ if specify_wait_period’ is False.

Type:

Returns a wait period label string formatted like

property etterslep_window: tuple[date, date]

Returns the start date and end date for the wait period.

Calculated by taking the start and end dates and adding the wait period to each.

property period_label: str

Returns a period label string formatted to Dapla standard.

to_query_params()

Returns a dict for parameterising SQL queries.

Return type:

dict[str, date]

property window: tuple[date, date]

Returns the start date and end date for the given period, as a tuple.

Both dates are within the period, so ‘end_date’ is the last day of the period. E.g. end of the month.

type PeriodType = Literal['year', 'halfyear', 'quarter', 'month', 'week']