This module provides two lightweight, immutable date wrapper classes — MonthEndDate and WeekendDate
Project description
📅 MonthEndDate & WeekendDate Utility
This module provides two lightweight, immutable date wrapper classes — MonthEndDate and WeekendDate — designed to normalize arbitrary dates to specific reference points in time (month-end or weekend).
Both classes support comparison (==, <, etc.) and hashing, allowing them to be used as dictionary keys or in sets.
🧩 Classes Overview
MonthEndDate
A utility class that always represents the last day of the given month.
✅ Behavior
- Any date or
(year, month)input is normalized to that month’s last calendar day. - Useful for financial or reporting systems where month-end aggregation is required.
📘 Example
from your_module import MonthEndDate
import datetime as dt
d = MonthEndDate(2025, 2, 10)
print(d) # MonthEndDate(2025-02-28)
print(d.to_date()) # datetime.date(2025, 2, 28)
# From arbitrary date
d2 = MonthEndDate.from_date(dt.date(2025, 10, 1))
print(d2) # MonthEndDate(2025-10-31)
⚙️ Comparison
MonthEndDate instances can be compared or used interchangeably with datetime.date:
MonthEndDate(2025, 3, 5) == dt.date(2025, 3, 31) # True
MonthEndDate(2025, 3, 5) < MonthEndDate(2025, 4, 1) # True
WeekendDate
A utility class that converts any given date into the Saturday of that week, where the week starts on Sunday.
✅ Behavior
weekday()is adjusted so that Sunday = 0, Saturday = 6.- The resulting date always represents the Saturday within the same Sunday-starting week.
📘 Example
from your_module import WeekendDate
import datetime as dt
# Convert arbitrary date to the Saturday of its week
WeekendDate(2025, 10, 12) # Sunday → 2025-10-18 (Sat)
WeekendDate(2025, 10, 14) # Tuesday → 2025-10-18 (Sat)
WeekendDate(2025, 10, 18) # Saturday → 2025-10-18 (Sat)
d = WeekendDate.from_date(dt.date(2025, 10, 19))
print(d.to_date()) # 2025-10-25
⚙️ Comparison
WeekendDate behaves like a regular datetime.date for equality and ordering:
WeekendDate(2025, 10, 15) == dt.date(2025, 10, 18) # True
WeekendDate(2025, 10, 15) < WeekendDate(2025, 10, 25) # True
🧠 Design Notes
- Both classes are immutable (
__slots__used, no attribute reassignment). - Implemented with
functools.total_ordering, providing rich comparison behavior. - Fully compatible with Python’s standard
datetimeoperations.
🧾 Typical Use Cases
- Financial data normalization (e.g., aligning transaction dates to month-end).
- Time-series aggregation by reporting period (month/week).
- Generating consistent reference dates for business analytics.
📦 Dependencies
-
Python standard library only:
datetimecalendarfunctools.total_ordering
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file datetf-0.1.0.tar.gz.
File metadata
- Download URL: datetf-0.1.0.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c60774879a45d423010b413d7dec9adff506cbb010ce3e2f255fa914329bc57b
|
|
| MD5 |
e3316ee7405a27978e205388a6fd6b29
|
|
| BLAKE2b-256 |
74519e90e2a9012b7891f31f2e4f34f4a9f713689a46143ea109b9350bcdb289
|
File details
Details for the file datetf-0.1.0-py3-none-any.whl.
File metadata
- Download URL: datetf-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0f4ffe2cfb207c5c89ee709e920ba3c3f0c367ef2494828c32d3c79f220b2dc9
|
|
| MD5 |
d046e3a43fb6362afa90306cb874f5bb
|
|
| BLAKE2b-256 |
0a100a96f7da7b98ae906addc1fd58eb52e60d96116eab0f3b594b3b7c1bbfdf
|