decimaldate Documentation
general |
|
|---|---|
docs |
|
code |
|
package |
|
downloads |
This documentation was generated Nov 19, 2024.
The source for this decimaldate project is available on GitHub.
Introduction
decimaldate is a Python utility package to handle integer dates on the form yyyymmdd.
Many times when you work with dates you encounter dates on the form yyyymmdd stored as integers.
Compared to other formats like ddmmyyyy, mmddyyyy, and mmddyy
this format is easily comparable (by using ìnt’s comparison operators < etc.) and thus sortable.
Convenience
As the base is an integer, there are no separators (e.g. - or /) used.
For convenience you can use a Python feature using underscores _ to improve readability
in your source code when writing int values
like: 2024_02_28 which is equivalent to 20240228 (or 2_0_2_4_0_2_2_8).
Using the underscore _ is a convenient separator for integers with information like:
dates, phone numbers, social security numbers, and zip codes.
The documentation and source code will use _ extensively to improve readability.
>>> 2024_03_12
20240312
This also works for strings when parsed as an integer:
>>> int("2024_03_12")
20240312
>>> from decimaldate import DecimalDate
>>> DecimalDate("2024_02_14")
DecimalDate(20240214)
Use
Creation
A DecimalDate accepts:
- No argument or
Nonewhich both will use today’s date >>> from decimaldate import DecimalDate >>> DecimalDate() DecimalDate(20240910)
>>> from decimaldate import DecimalDate >>> DecimalDate(None) DecimalDate(20240910)
inton the formyyyymmdd>>> from decimaldate import DecimalDate >>> DecimalDate(2024_03_12) DecimalDate(20240312)
stron the formyyyymmdd>>> from decimaldate import DecimalDate >>> DecimalDate("2024_03_12") DecimalDate(20240312)
datetime.date>>> from decimaldate import DecimalDate >>> from datetime import date >>> DecimalDate(date.today()) DecimalDate(20240910)
datetime.datetime>>> from decimaldate import DecimalDate >>> from datetime import datetime >>> DecimalDate(datetime.today()) DecimalDate(20240910)
Class Utilities and Convenience
See the usage page.
Instance Utilities and Convenience
See the usage page.
Example
Loop over all Tuesdays in the month of Valentine’s Day 2024.
>>> from decimaldate import DecimalDateRange
>>>
>>> TUESDAY = 1
>>>
>>> for dd in [
>>> dd
>>> for dd in DecimalDateRange.range_month_of_decimal_date(20240214)
>>> if dd.weekday() == TUESDAY
>>> ]:
>>> print(repr(dd))
DecimalDate(20240206)
DecimalDate(20240213)
DecimalDate(20240220)
DecimalDate(20240227)


