API Reference

Dekad

class kalendar.Dekad(year: int, dekad: int)

Dekad extension for datetime.date.

Extension of the datetime.date base class for dekads. Uses standard yearly definition of dekad where each month is composed of 3 dekads, the first 2 comprising the first 1-10, and 11-20 days respectively, and the third dekad comprising all remaining days of the month. Under the hood, each Dekad is stored as the first day of the dekad, so the 1st dekad of a month is the 1st, the 2nd is on the 11th, and the 3rd is on the 21st. Extension of datetime.date allows for comparison of dekads and conversion between classes and use of existing constructors, methods, and properties, with some additions detailed below. For the purposes of the class structure, the yearly definition is relied on, but the monthly dekad (1st to 3rd) can be accessed using dekad_monthly.

Base constructor takes year and dekad. Can also be constructed directly from datetime.date or datetime.datetime objects and use any datetime.date constructors:

fromdate() fromdatetime() fromisoformat() fromisocalendar() fromtimestamp() fromordinal()

Method to return datetime.date object added, todate(). Other methods remain available. Read-only properties dekad and dekad_monthly added alongside year, month, and day.

Parameters:
  • year (int) – Year.

  • dekad (int) – Dekad, from 1 to 36.

Examples

>>> d = Dekad(2022, 1)
>>> d
Dekad(2022, 1)
>>> d.todate()
datetime.date(2022, 1, 1)
>>> d - 1
Dekad(2021, 36)
>>> d.dekad
1
__add__(other: int | timedelta) Dekad | date

Addition magic method for dekads.

For integers, adds that to the dekads and returns a new Dekad object. Otherwise, follows the behavior of datetime.date.

Examples

>>> d = Dekad(2021, 36)
>>> d + 1
Dekad(2022, 1)
Returns:

Returns Dekad if adding integer, or datetime.date otherwise.

Return type:

Union[Dekad, datetime.date]

__sub__(other: int | Dekad | timedelta) Dekad | int | timedelta

Subtraction magic method for dekads.

For integers, subtracts that from the dekads. Dekads can also be subtracted from each other, returning the number of dekads between. Otherwise, follows the behavior of datetime.date.

Examples

>>> import datetime
>>>
>>> d1 = Dekad(2022, 1)
>>> d2 = Dekad(2021, 1)
>>> d1 - 1
Dekad(2021, 36)
>>> d1 - d2
36
>>> d1 - datetime.date(2021, 12, 30)
datetime.timedelta(days=2)
Returns:

Returns Dekad if subtracting integer, or int if subtracting another Dekad, and datetime.timedelta otherwise.

Return type:

Union[Dekad, int, datetime.timedelta]

property dekad: int

Dekad of the year, 1 to 36.

property dekad_monthly: int

Dekad of the month, 1 to 3.

classmethod fromdate(d: date) Dekad

Construct a dekad from a datetime.date object.

classmethod fromdatetime(dt: datetime) Dekad

Construct a dekad from a datetime.date object.

classmethod fromisocalendar(year: int, week: int, day: int) Dekad

Construct a dekad from the ISO year, week number and weekday.

classmethod fromisoformat(time_string: str) Dekad

Construct a dekad from a string in one of the ISO 8601 formats.

classmethod fromordinal(n: int) Dekad

Construct a dekad from a proleptic Gregorian ordinal.

January 1 of the year 1 is day 1. Only the year, month and day are non-zero in the result.

classmethod fromtimestamp(timestamp: float) Dekad

Construct a dekad from a POSIX timestamp (like time.time()).

todate() date

Convert to datetime.date object for the year, month, and day.

Pentad

class kalendar.Pentad(year: int, pentad: int)

Pentad extension for datetime.date.

Extension of the datetime.date base class for pentads. Uses standard yearly definition of pentads where the 365 day calendar year is divided into 73 pentads of 5 days each. Under the hood, each Pentad is stored as the first day of the pentad, the 1st pentad of the year is on January 1st, the 2nd on January 6th, and so on. Leap years have 366 days, and pentad 12 is extended comprise 6 days that includes February 29th. Extension of datetime.date allows for comparison of pentads and conversion between classes and use of existing constructors, methods, and properties, with some additions detailed below.

Base constructor takes year and pentad. Can also be constructed directly from datetime.date or datetime.datetime objects and use any datetime.date constructors:

fromdate() fromdatetime() fromisoformat() fromisocalendar() fromtimestamp() fromordinal()

Method to return datetime.date object added, todate(). Other methods remain available. Read-only property pentad added alongside year, month, and day.

Parameters:
  • year (int) – Year.

  • pentad (int) – Pentad, from 1 to 73.

Examples

>>> p = Pentad(2022, 1)
>>> p
Pentad(2022, 1)
>>> p.todate()
datetime.date(2022, 1, 1)
>>> p - 1
Pentad(2021, 73)
>>> p.pentad
1
__add__(other: int | timedelta) Pentad | date

Addition magic method for pentads.

For integers, adds that to the pentads and returns a new Pentad object. Otherwise, follows the behavior of datetime.date.

Examples

>>> p = Pentad(2021, 73)
>>> p + 1
Pentad(2022, 1)
Returns:

Returns Pentad if adding integer, or datetime.date otherwise.

Return type:

Union[Pentad, datetime.date]

__sub__(other: int | Pentad | timedelta) Pentad | int | timedelta

Subtraction magic method for pentads.

For integers, subtracts that from the pentads. Pentads can also be subtracted from each other, returning the number of pentads between. Otherwise, follows the behavior of datetime.date.

Examples

>>> import datetime
>>>
>>> p1 = Pentad(2022, 1)
>>> p2 = Pentad(2021, 1)
>>> p1 - 1
Pentad(2021, 73)
>>> p1 - p2
73
>>> p1 - datetime.date(2021, 12, 30)
datetime.timedelta(days=2)
Returns:

Returns Pentad if subtracting integer, or int if subtracting another Pentad, and datetime.timedelta otherwise.

Return type:

Union[Pentad, int, datetime.timedelta]

classmethod fromdate(d: date) Pentad

Construct a pentad from a datetime.date object.

classmethod fromdatetime(dt: datetime) Pentad

Construct a pentad from a datetime.date object.

classmethod fromisocalendar(year: int, week: int, day: int) Pentad

Construct a pentad from the ISO year, week number and weekday.

classmethod fromisoformat(time_string: str) Pentad

Construct a pentad from a string in one of the ISO 8601 formats.

classmethod fromordinal(n: int) Pentad

Construct a pentad from a proleptic Gregorian ordinal.

January 1 of the year 1 is day 1. Only the year, month and day are non-zero in the result.

classmethod fromtimestamp(timestamp: float) Pentad

Construct a pentad from a POSIX timestamp (like time.time()).

property pentad: int

Pentad of the year, 1 to 73.

todate() date

Convert to datetime.date object for the year, month, and day.