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 only has 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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file weekdays_enum-0.1.0.tar.gz.
File metadata
- Download URL: weekdays_enum-0.1.0.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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
938c6a93e476ca419e5d36549d8caf32c4edce897d6e6f57beff72b2d45c5e70
|
|
| MD5 |
549c6918b944a8df5c9eb60a2a89ce1c
|
|
| BLAKE2b-256 |
0cb99acec22b69eeed7a09e2c275115517a2af0c588b7a42ec05b47a419a5429
|
File details
Details for the file weekdays_enum-0.1.0-py3-none-any.whl.
File metadata
- Download URL: weekdays_enum-0.1.0-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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b814b79c0d732a4195c905f6e807b16abab1a70760142055b0f6bb906cab3f5c
|
|
| MD5 |
0b4321dbe23561806ea82a0fe7a81455
|
|
| BLAKE2b-256 |
10d1456049bf585323e7e578b3536fd0557460628431ff74cf96a50643daeca0
|