Skip to content

datethyme.Date

This is the documentation page for the Date class.

datethyme.Date

Bases: BaseModel

Bespoke immutable date class designed to simplify working with dates, in particular input parsing, date calculations, and ranges.

datetime property

datetime: DateTime

day class-attribute instance-attribute

day: int = Field(ge=1, le=31, frozen=True)

end property

end: DateTime

model_config class-attribute instance-attribute

model_config = ConfigDict(frozen=True)

month class-attribute instance-attribute

month: int = Field(ge=1, le=12, frozen=True)

ordinal property

ordinal: int

prose property

prose: str

Prose English date string of the form Wednesday, March 17th 2025.

span property

span: DateTimeSpan

start property

start: DateTime

stdlib property

stdlib: date

weekday property

weekday: WeekdayLiteral

weekday_ordinal property

weekday_ordinal: int

year class-attribute instance-attribute

year: int = Field(ge=1, le=1000000, frozen=True)

__add__

__add__(days: int) -> Date

Create a new date days later than self.

__and__

__and__(time: Time | DateTime) -> DateTime

__bool__

__bool__() -> bool

__eq__

__eq__(other: object) -> bool

__ge__

__ge__(other: Any) -> bool

__gt__

__gt__(other: Any) -> bool

__hash__

__hash__() -> int

__int__

__int__() -> int

__le__

__le__(other: Any) -> bool

__lt__

__lt__(other: Any) -> bool

__pow__

__pow__(other: Date) -> DateRange

__repr__

__repr__() -> str

__str__

__str__() -> str

__sub__

__sub__(subtrahend: int) -> Date
__sub__(subtrahend: Date) -> int
__sub__(subtrahend: Date | int) -> Date | int

days_to

days_to(date2: Date) -> int

format

format(template: str) -> str

Returns a the date written out in long form.

from_ordinal classmethod

from_ordinal(ord: int) -> Date

if_valid classmethod

if_valid(date_string: str) -> Self | None

Parse a string and return an instance of Date if possible; otherwise None.

parse classmethod

parse(date_string: str) -> Self

Alias for model_validate, but expects a string.

range

range(end: Date | int, inclusive: bool = False) -> list[Date]

Returns a list of consecutive days, default non-inclusive as is standard in Python. Supports reverse-order ranges.

serialize_date

serialize_date() -> str

today classmethod

today() -> Date

Return todays date, using datetime.date.today() from the Python standard library.

tomorrow classmethod

tomorrow() -> Date

validate_raw_date classmethod

validate_raw_date(raw_date: str | dict | list | tuple) -> dict[str, str | int | float]