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 (or WeekDayBaseEnglish a base where the english days of the week are abstract and required).

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

# Or implement your own
from weekdays_enum.weekday_base import WeekDayBase, WeekDayBaseEnglish


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

class MyWeeksdag(WeekDayBase):
    Maandag = 0
    Dinsdag = 1
    ...

You can also import specific days

from weekdays_enum.monday_start import Monday, Tuesday

or just all the days to use without WeekDay.

from weekdays_enum.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_enum.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_enum.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.2.0.tar.gz (7.2 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.2.0-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: weekdays_enum-0.2.0.tar.gz
  • Upload date:
  • Size: 7.2 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.2.0.tar.gz
Algorithm Hash digest
SHA256 a4a26255e53d425a29b1928d68040af7f33af467bac5c62afca6042ee9a2ef58
MD5 ac2fa38f3973dc48b44e8e2d1565ecd3
BLAKE2b-256 2a4914a52f6aba25ea4acd8afde17791a87b8755f9d4226a1ea7a71c54c0adae

See more details on using hashes here.

File details

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

File metadata

  • Download URL: weekdays_enum-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.1 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.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4641c9a5f361be6ad51b98659285a936963e1497a10453333925216e2a58256e
MD5 3bcded2dfe595c6002bf9199eded2399
BLAKE2b-256 72caa4b1e6f71eba9099f5256a797ea363bde9929042e503fbe6444b287a3a11

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