Justdays
Package to make working with days and ranges of days in Python super easy.
The package contains two classes:
Day handles everything you want to do with days.
Period handles a range of Day objects.
Current version: 1.9.2
Installation
python -m pip install justdays
Day class usage
Initializing a Day
day = Day() # No arguments, initalize with the current day
day = Day('2022-08-16') # One argument, string in YYYY-MM-DD format
day = Day(2022, 32) # Two arguments: year, week. Day with be the Monday of that week
day = Day(2022, 8, 16) # Three arguments: year, month, day.
day = Day(datetime(2022, 8, 16)) # Initialize with Python datetime object
day = Day(date(2022, 8, 16)) # Initialize with Python date object
Accessing Day fields
d = day.d # int
m = day.m # int
y = day.y # int
as_string = day.str # in YYYY-MM-DD format
Represenation
str(day) # Returns the day in YYYY-MM-DD format
day.as_datetime() # Returns the day as a Python datetime object
day.as_date() # Returns the day as a Python date object
day.strftime(format_string) # Returns the day as a string formatted according to the format string
day.as_unix_timestamp() # Returns the day as a unix timestamp (int)
Days further away or in the past
day.next() # Next day
day + 1 # Next day
1 + day # Next day
day.previous() # Previous day
day - 1 # Previous day
day.next_weekday() # Next day that is on a weekday
day.previous_weekday() # Previous day that is on a weekday
day.plus_days(3) # Add 3 days to the day
day + 3
day.plus_days(-3) # Subtract 3 days from the day
day.plus_weeks(1) # Add 1 week to the day
day.plus_months(1) # Add 1 month to the day
Comparing days
day1 = Day('2022-08-16')
day2 = Day('2022-08-20')
day2 > day1 # Returns True if day2 is after day1
day2 == day1 # Returns True if day2 is the same day as day1
days_difference = day2 - day1 # Returns the difference in days between two days (4)
Miscellaneous
day.is_weekend() # Returns True if the day is a weekend
day.is_weekday() # Returns True if the day is a weekday
day.day_of_week() # Returns the day of the week as an integer (0 = Monday, 6 = Sunday)
day.day_of_year() # Returns the day of the year as an integer (1 = 1st of January, 365 = 31st of December in a non leap year)
day.fraction_of_the_year_past() # Returns the fraction of the year that has passed (0.0 = 1st of January, 1.0 = 31st of December)
day.week_number() # Returns the week number of the year (1 = first week of the year, 52 = last week of the year)
day.last_monday() # Returns the last day that was a Monday or the day itself if it is a Monday
day.last_day_of_month() # Returns the last day of the month of the day
day + ' is a nice day' # Add string to a day
'The date is ' + day # Add string to a day
Period class usage
Period is just a day range. Either fromday or untilday can be left to None
Initializing a Period
period = Period(day1, day2) # Period ranging from day1 (included) until day2 (not included)
period = Period(day1) # One argument: fromday. Untilday is left open
period = Period('2022-08-16', '2022-08-20') # Period can be initialized with strings in YYYY-MM-DD format
period = Period.from_week(2022, 32) # Period ranging from the Monday of week 32 until the Sunday of week 32
period = Period.from_month(2022, 8) # Period ranging from the 1st of August until the 31st of August
Accessing Period fields
fromday = period.fromday
untilday = period.untilday
length = len(period) # Returns maximum integer value for open-ended periods
Iterating over a Period
for day in period:
print(day)
Checking if a Day falls within a Period
if day in period:
print('yes!')
Operations with Periods
overlap = period1 & period2 # Calculate overlap between two periods
union = period1 | period2 # Calculate union of two periods
if period1.intersects(period2):
print("Periods overlap")
Additional Period methods
if period.is_empty():
print("Period has no duration")
if period: # Truthy operator, returns True if period is not empty
print("Period is not empty")
shifted_period = period.shift(7) # Move period 7 days forward
split_periods = period.split(30) # Split period into 30-day chunks
Metadata
Release files for justdays 1.9.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| justdays-1.9.3.tar.gz | 7.9 kB | Without provenance | Details for justdays-1.9.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| justdays-1.9.3-py3-none-any.whl | Python 3 | none | any | Details for justdays-1.9.3-py3-none-any.whl |
Total release size: 15.8 kB
Release files / justdays-1.9.3.tar.gz
| Download URL | justdays-1.9.3.tar.gz |
|---|---|
| Size | 7.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b894b33d9df7a83e8d5f10764f57dca7b91eed4d5e431205a99eb743e0109939
|
|
BLAKE2b-256 checksum How to use checksums |
eeb4d6331e0f220044cac18ed493519c9fcb7e2dac52e924b8ab51010004a9ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.3
|
Release files / justdays-1.9.3-py3-none-any.whl
| Download URL | justdays-1.9.3-py3-none-any.whl |
|---|---|
| Size | 7.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
374202334842fbce290560060b38ff01808c36bbbec89b99d11079ff71ce7cbc
|
|
BLAKE2b-256 checksum How to use checksums |
bfcc928c8be3ab5607cfb3a1617d60f64ca234696b84f1d02ea942be073e7f67
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.11.3
|
Security for justdays 1.9.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.