Skip to main content

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

Release files for calendarweek 0.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for calendarweek 0.6
File Size Uploaded
calendarweek-0.6.tar.gz 8.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for calendarweek 0.6
File Interpreter ABI Platform
calendarweek-0.6-py3-none-any.whl Python 3 none any Details

Total release size: 19.9 kB

Release files / calendarweek-0.6.tar.gz

Download URL calendarweek-0.6.tar.gz
Size 8.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8df37a60efe7324a91c1c1520a8faf67d04c0ebe450317fda6124b58fb6f7e1e
BLAKE2b-256 checksum
How to use checksums
f46f40ae1080331ea03aff921b7c5c099b3acdc8261c21875402635742a7f5d8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/6.5.0-1-rt-amd64

Release files / calendarweek-0.6-py3-none-any.whl

Download URL calendarweek-0.6-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b9b55013ff0288275445c0cb546b6ceb9ed02874819f9649f78479e48cb30786
BLAKE2b-256 checksum
How to use checksums
1eef7687a7cafed01cb211bcba3d579f0b624f65d93aeabb75b271b955a409d2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.6.1 CPython/3.11.5 Linux/6.5.0-1-rt-amd64

Release history Release notifications | RSS feed

This release

0.6 This release

2 release files

0.5.3

2 release files

0.5.2

2 release files

0.5.1

2 release files

0.5.0

2 release files

0.4.7

2 release files

0.4.6

2 release files

0.4.5

2 release files

0.4.4

2 release files

0.4.3

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page