Skip to content

rencal.core.short_date

rencal.core.short_date defines year-agnostic month/day values used by bucket definitions.

ShortDate stores month/day pairs, validates them against non-leap-year semantics for deterministic partitioning, and implements rich comparison operators so it can be ordered and searched efficiently inside bucket definitions.

import datetime as dt
from rencal.core.short_date import ShortDate
start = ShortDate.from_list([1, 1])
end = ShortDate(dt.datetime(2024, 3, 1))
assert start < end
class ShortDate: ShortDate

Stores month/day and provides context-aware conversion/comparison utilities.

  • date datetime.datetime | Any

    Any object exposing month and day integer attributes.

Returns ShortDate

from_dict(date_dictionary: dict) -> ShortDate

Builds short date from dictionary containing month and day.

  • date_dictionary dict

    Dictionary with month and day keys.

Returns ShortDate

from_list(date_list: list) -> ShortDate

Builds short date from two-item [month, day] list.

  • date_list list

    Two-item list of [month, day].

Returns ShortDate

to_datetime(context_year: int) -> datetime.datetime

Converts short date to datetime with provided context year.

  • context_year int

    Year used as the context for conversion.

Returns datetime.datetime

add_with_context(timedelta: datetime.timedelta, context_year: int) -> datetime.datetime

Adds timedelta to short date in supplied context year.

  • timedelta datetime.timedelta

    Time delta to add.

  • context_year int

    Year used as the context for conversion.

Returns datetime.datetime

subtract_with_context(timedelta: datetime.timedelta, context_year: int) -> datetime.datetime

Subtracts timedelta from short date in supplied context year.

  • timedelta datetime.timedelta

    Time delta to subtract.

  • context_year int

    Year used as the context for conversion.

Returns datetime.datetime

__sub__(timedelta: datetime.timedelta | ShortDate) -> ShortDate | int

Subtracts timedelta to shift short date or computes day distance to another short date.

Returns ShortDate | int

__gt__(date: ShortDate) -> bool

Compares two short dates using leap-year context for full date ordering.

Returns bool

__lt__(date: ShortDate) -> bool

Compares two short dates using leap-year context for full date ordering.

Returns bool

__ge__(date: ShortDate) -> bool

Compares two short dates using leap-year context for full date ordering.

Returns bool

__le__(date: ShortDate) -> bool

Compares two short dates using leap-year context for full date ordering.

Returns bool

__eq__(date: ShortDate) -> bool

Compares two short dates using leap-year context for equality checks.

Returns bool

Month value of the short date.

Type int

Raises

  • TypeError: If month is not an integer.
  • ValueError: If month is outside [1, 12].

Day value of the short date.

Type int

Raises

  • TypeError: If day is not an integer.
  • ValueError: If day is not valid for the configured month.

Default monthly short-date bucket boundaries.

Type list[ShortDate]

Default weekly short-date bucket boundaries.

Type list[ShortDate]