annual.datecalc

Date calculations for the parser.

Functions

wd_of_month(→ datetime.date | None)

Compute the n-th occurrence of a weekday in a month.

last_wd_of_month(→ datetime.date)

Compute the last occurrence of a weekday in a month.

wd_relative_to(→ datetime.date)

Compute when a weekday occurs relative to a given date.

days_relative_to(→ datetime.date)

Add given number of days to the given date.

Module Contents

annual.datecalc.wd_of_month(year: int, month: annual.model.Month, ordinal: int, week_day: annual.model.WeekDay) datetime.date | None

Compute the n-th occurrence of a weekday in a month.

Ensures that the result is in the given year and month. If the request cannot be fulfilled, None is returned.

Parameters:
  • year (int) – the (full four-digit) year for which the date should be computed

  • month (Month) – the month for which the date is to be computed

  • ordinal (int) – if set to 1 (resp. 2, 3, …) the first (second, third, …) occurrence of the given weekday is computed,

  • week_day (WeekDay) – the weekday of the result

Returns:

The requested date, or None if no such date exists

Return type:

datetime.date | None

annual.datecalc.last_wd_of_month(year: int, month: annual.model.Month, week_day: annual.model.WeekDay) datetime.date

Compute the last occurrence of a weekday in a month.

annual.datecalc.wd_relative_to(recurrence: datetime.date, week_day: annual.model.WeekDay, direction: int, include_start: bool) datetime.date

Compute when a weekday occurs relative to a given date.

Parameters:
  • recurrence (datetime.date) – the start date relative to which the result is computed

  • week_day (WeekDay) – the weekday of rhe target date

  • direction (int) – must be 1 to compute a date after the start date or -1 to compute a date before

  • include_start (bool) – skip one week if the week day of the start date matches

Returns:

the first occurrence of the given weekday before or after the given date

Return type:

datetime.date

annual.datecalc.days_relative_to(recurrence: datetime.date, num_days: int) datetime.date

Add given number of days to the given date.

Parameters:
  • recurrence (datetime.date) – start date to which days are added

  • num_days (int) – number of days to add

Returns:

the recurrence date plus the given number of days

Return type:

datetime.date