Utilities for working with calendar weeks in Python and Django
Project description
python-calendarweek provides a CalendarWeek dataclass for representing one week in a year, and utility functions to work with it in pure Python or Django.
Usage
The CalendarWeek object
The main interface is the CalendarWeek object. The following example shows its interface.
from datetime import date
from calendarweek import CalendarWeek
# Create an object for the third week in 2012
week = CalendarWeek(year=2012, week=3)
# Get the current week (or the week for any date)
week = CalendarWeek.from_date(date.today())
# Short-hand for the current week
week = CalendarWeek()
# Get all weeks within a date range
start = date(2012, 3, 18)
end = date(2012, 4, 19)
weeks = CalendarWeek.weeks_within(start, end)
# Get the last week of a year
week = CalendarWeek.get_last_week_of_year(2012)
# Get the Wednesday of the selected week (or any weekday)
day = week[3]
# Check whether a day is within a week
is_contained = day in week
# Get the week five weeks later
week = week + 5
# Additionally, all comparison operators are implemented
Django utilities
Some utilities for Django are contained in the calendarweek.django module:
i18n_day_names — Returns a tuple of localised day names
i18n_day_abbrs — Returns a tuple of abbreviated, localised day names
i18n_month_names — Returns a tuple of localised month names
i18n_month_abbrs — Returns a tuple of abbreviated, localised month names
All the above for suffixed with _choices to get a list of tuples ready for a model or form field’s choices
i18n_js — A view returning the above as JSON ready to be consumed by a frontend
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
File details
Details for the file calendarweek-0.6.tar.gz
.
File metadata
- Download URL: calendarweek-0.6.tar.gz
- Upload date:
- Size: 8.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.5.0-1-rt-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8df37a60efe7324a91c1c1520a8faf67d04c0ebe450317fda6124b58fb6f7e1e |
|
MD5 | 23875c12f807d60a61c69f07ca768b88 |
|
BLAKE2b-256 | f46f40ae1080331ea03aff921b7c5c099b3acdc8261c21875402635742a7f5d8 |
File details
Details for the file calendarweek-0.6-py3-none-any.whl
.
File metadata
- Download URL: calendarweek-0.6-py3-none-any.whl
- Upload date:
- Size: 11.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.11.5 Linux/6.5.0-1-rt-amd64
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9b55013ff0288275445c0cb546b6ceb9ed02874819f9649f78479e48cb30786 |
|
MD5 | 256349c1ff872d67eab977e0874cab03 |
|
BLAKE2b-256 | 1eef7687a7cafed01cb211bcba3d579f0b624f65d93aeabb75b271b955a409d2 |