API Reference
Dekad
- class kalendar.Dekad(year: int, dekad: int)
Dekad extension for
datetime.date.Extension of the
datetime.datebase 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, eachDekadis 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 ofdatetime.dateallows 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 usingdekad_monthly.Base constructor takes year and dekad. Can also be constructed directly from
datetime.dateordatetime.datetimeobjects and use anydatetime.dateconstructors:fromdate()fromdatetime()fromisoformat()fromisocalendar()fromtimestamp()fromordinal()Method to return
datetime.dateobject added,todate(). Other methods remain available. Read-only propertiesdekadanddekad_monthlyadded 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
Dekadobject. Otherwise, follows the behavior ofdatetime.date.Examples
>>> d = Dekad(2021, 36) >>> d + 1 Dekad(2022, 1)
- Returns:
Returns
Dekadif adding integer, ordatetime.dateotherwise.- 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
Dekadif subtracting integer, orintif subtracting anotherDekad, anddatetime.timedeltaotherwise.- 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 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.datebase 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, eachPentadis 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 ofdatetime.dateallows 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.dateordatetime.datetimeobjects and use anydatetime.dateconstructors:fromdate()fromdatetime()fromisoformat()fromisocalendar()fromtimestamp()fromordinal()Method to return
datetime.dateobject added,todate(). Other methods remain available. Read-only propertypentadadded 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
Pentadobject. Otherwise, follows the behavior ofdatetime.date.Examples
>>> p = Pentad(2021, 73) >>> p + 1 Pentad(2022, 1)
- Returns:
Returns
Pentadif adding integer, ordatetime.dateotherwise.- 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
Pentadif subtracting integer, orintif subtracting anotherPentad, anddatetime.timedeltaotherwise.- Return type:
Union[Pentad, int, datetime.timedelta]
- 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.