Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

calendarweek-0.5.2.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

calendarweek-0.5.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file calendarweek-0.5.2.tar.gz.

File metadata

  • Download URL: calendarweek-0.5.2.tar.gz
  • Upload date:
  • Size: 9.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.10

File hashes

Hashes for calendarweek-0.5.2.tar.gz
Algorithm Hash digest
SHA256 6f9a86d8fb7ba0e321138b257a6883e6b8f105932bf03fed69491787866a122b
MD5 e6996d594099e2365818b77994aa1187
BLAKE2b-256 f8bb33b24ab0f020406c104c50233bd4fc89f8b6f3c0acc1b92404fbc4777d62

See more details on using hashes here.

Provenance

File details

Details for the file calendarweek-0.5.2-py3-none-any.whl.

File metadata

  • Download URL: calendarweek-0.5.2-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.6.4 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.57.0 CPython/3.9.10

File hashes

Hashes for calendarweek-0.5.2-py3-none-any.whl
Algorithm Hash digest
SHA256 de24d6f7355c1ae2a391207e67415bd35d88c9ede6742a64b5cfdfaffb373bd3
MD5 8fb8d416313387377c3792717b107e12
BLAKE2b-256 5898e426f205918077ccd01a0c9a138805509d0b9d0c85f13f2c450e4627043b

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page