Skip to main content

A super lightweight thoroughly tested package to make dealing with the days of a week a little easier.

Project description

weekdays-enum

A super lightweight thoroughly tested package to make dealing with the days of a week a little easier.

Far too often I see hard coded lists of strings representing the days of the week days = ['Monday', 'Tuesday', ...], or imports of unnecessarily large and often out of date packages just to deal with days of the week coming from something like json or user input. weekdays-enum aims to solve these issues and more.

Note weekdays-enum depends on one, even smaller, dependency by the same auther: ordered-string-enum

See the sourcecode here.

Installation

pip install weekdays-enum

Usage

The weekdays-enum package provides two enum class definitions called WeekDay one for weeks starting on Monday, the other for starting on Sunday. Import the WeekDay needed or create your own implementation by extending WeekDayBase.

from weekdays.monday_start import WeekDay
# Or if weeks start on Sunday
from weekdays.sunday_start import WeekDay

# Or implement your own
from weekdays.weekday_base import WeekDayBase

class MyWeekDay(WeekDayBase):
  Wednesday = 0
  Thursday  = 1
  ...

You can also import specific days

from weekdays.monday_start import Monday, Tuesday

or just all the days to use without WeekDay.

from weekdays.monday_start import *

print(Monday)

Comparisons and Ordering

WeekDay enums are powerful in that they can be retrieved in a number of convenient ways and can be seamlessly compared with each-other, their int values, or even strings:

import datetime
from weekdays.monday_start import *

print('Compare Monday to Tuesday in 4 equivalent ways')
print(Monday < Tuesday)   # - True
print(Monday < 1)         # - True
print(Monday < 'Tuesday') # - True
print(Monday < 'tuesday') # - True

print('Get the WeekDay easily and intuitively')
first_Monday_2026 = datetime.datetime(2026, 1, 5)
print(WeekDay(0))                               # - <WeekDay.Monday: 0>
print(WeekDay('Monday'))                        # - <WeekDay.Monday: 0>
print(WeekDay('monday'))                        # - <WeekDay.Monday: 0>
print(WeekDay.get_week_day(first_Monday_2026))  # - <WeekDay.Monday: 0>
print(WeekDay.from_iso_day(1))                  # - <WeekDay.Monday: 0>

No more hard coding a list of the days of the week. We can get an ordered list from WeekDay and a desired string representing each day:

from weekdays.monday_start import *
days = WeekDay.list() # gets an ordered list containing each day

for day in days:
  print(f'{day.name} or "{day.short()}" for short or "{day.short(2)}" for even shorter')

Outputs:

Monday or "Mon" for short or "Mo" for even shorter
Tuesday or "Tue" for short or "Tu" for even shorter
Wednesday or "Wed" for short or "We" for even shorter
Thursday or "Thu" for short or "Th" for even shorter
Friday or "Fri" for short or "Fr" for even shorter
Saturday or "Sat" for short or "Sa" for even shorter
Sunday or "Sun" for short or "Su" for even shorter

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

weekdays_enum-0.1.1.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weekdays_enum-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file weekdays_enum-0.1.1.tar.gz.

File metadata

  • Download URL: weekdays_enum-0.1.1.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for weekdays_enum-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3caebac88bcea5ab5f56184fac8169d6ed50a69ab178c6b686ab58d39c5dc282
MD5 5d99744295df42db8fb623259da8063e
BLAKE2b-256 8734c4a4e726d0ca0d9035ee64fb818fed6333fe80f4614f1bb828a880c070a3

See more details on using hashes here.

File details

Details for the file weekdays_enum-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: weekdays_enum-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for weekdays_enum-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 140b60334993ac3be243131b0c398839760457f659ea4deed3e428bf8d19942e
MD5 fd42e5b10123721ef78c2bfa89baac66
BLAKE2b-256 fa0d93b936957b877fb98ede0a8c04ec00d13ba2e7191c33e3c81c03a6f1620e

See more details on using hashes here.

Supported by

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