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.
Example
Section titled “Example”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 < endConstructor
Section titled “Constructor”ShortDate
Section titled “ShortDate”class ShortDate: ShortDateStores month/day and provides context-aware conversion/comparison utilities.
Parameters
Section titled “Parameters”
Any object exposingdatedatetime.datetime|Anymonthanddayinteger attributes.
Returns ShortDate
Methods
Section titled “Methods”ShortDate.from_dict
Section titled “ShortDate.from_dict”from_dict(date_dictionary: dict) -> ShortDateBuilds short date from dictionary containing month and day.
Parameters
Section titled “Parameters”
Dictionary withdate_dictionarydictmonthanddaykeys.
Returns ShortDate
ShortDate.from_list
Section titled “ShortDate.from_list”from_list(date_list: list) -> ShortDateBuilds short date from two-item [month, day] list.
Parameters
Section titled “Parameters”
Two-item list ofdate_listlist[month, day].
Returns ShortDate
ShortDate.to_datetime
Section titled “ShortDate.to_datetime”to_datetime(context_year: int) -> datetime.datetimeConverts short date to datetime with provided context year.
Parameters
Section titled “Parameters”
Year used as the context for conversion.context_yearint
Returns datetime.datetime
ShortDate.add_with_context
Section titled “ShortDate.add_with_context”add_with_context(timedelta: datetime.timedelta, context_year: int) -> datetime.datetimeAdds timedelta to short date in supplied context year.
Parameters
Section titled “Parameters”-
Time delta to add.timedeltadatetime.timedelta -
Year used as the context for conversion.context_yearint
Returns datetime.datetime
ShortDate.subtract_with_context
Section titled “ShortDate.subtract_with_context”subtract_with_context(timedelta: datetime.timedelta, context_year: int) -> datetime.datetimeSubtracts timedelta from short date in supplied context year.
Parameters
Section titled “Parameters”-
Time delta to subtract.timedeltadatetime.timedelta -
Year used as the context for conversion.context_yearint
Returns datetime.datetime
ShortDate.sub
Section titled “ShortDate.sub”__sub__(timedelta: datetime.timedelta | ShortDate) -> ShortDate | intSubtracts timedelta to shift short date or computes day distance to another short date.
Returns ShortDate | int
ShortDate.gt
Section titled “ShortDate.gt”__gt__(date: ShortDate) -> boolCompares two short dates using leap-year context for full date ordering.
Returns bool
ShortDate.lt
Section titled “ShortDate.lt”__lt__(date: ShortDate) -> boolCompares two short dates using leap-year context for full date ordering.
Returns bool
ShortDate.ge
Section titled “ShortDate.ge”__ge__(date: ShortDate) -> boolCompares two short dates using leap-year context for full date ordering.
Returns bool
ShortDate.le
Section titled “ShortDate.le”__le__(date: ShortDate) -> boolCompares two short dates using leap-year context for full date ordering.
Returns bool
ShortDate.eq
Section titled “ShortDate.eq”__eq__(date: ShortDate) -> boolCompares two short dates using leap-year context for equality checks.
Returns bool
Properties
Section titled “Properties”ShortDate.month
Section titled “ShortDate.month”Month value of the short date.
Type int
Raises
TypeError: If month is not an integer.ValueError: If month is outside [1, 12].
ShortDate.day
Section titled “ShortDate.day”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.
Constants
Section titled “Constants”MONTHLY_BUCKET_DEFINITION
Section titled “MONTHLY_BUCKET_DEFINITION”Default monthly short-date bucket boundaries.
Type list[ShortDate]
WEEKLY_BUCKET_DEFINITION
Section titled “WEEKLY_BUCKET_DEFINITION”Default weekly short-date bucket boundaries.
Type list[ShortDate]

