A simple library for common date and time manipulations
Reason this release was yanked:
Broken LICENSE link in README; use 1.0.0 or later instead.
Project description
dttools
A simple Python library for common date and time manipulations.
Installation
pip install dttools
Requires Python 3.10+. Uses the standard library's zoneinfo for timezones
(no pytz). On Windows, tzdata is pulled in automatically.
Usage
Adding (or subtracting) business days
from dttools import add_business_days
from datetime import datetime, date
start_date = datetime(2023, 11, 10)
add_business_days(start_date, 5) # 5 business days forward, skipping weekends
add_business_days(start_date, -3) # 3 business days backward
# Optionally skip holidays too
add_business_days(start_date, 5, holidays={date(2023, 11, 23)})
Counting business days between two dates
from dttools import days_between_in_business_days
from datetime import datetime
days_between_in_business_days(datetime(2023, 11, 1), datetime(2023, 11, 10))
# Counts weekdays from start (inclusive) up to end (exclusive).
Checking business days and weekends
from dttools import is_business_day, is_weekend
from datetime import date
is_business_day(date(2023, 11, 10)) # True (Friday)
is_business_day(date(2023, 11, 11)) # False (Saturday)
is_weekend(date(2023, 11, 11)) # True
Human-readable relative dates
from dttools import format_relative_date
from datetime import datetime, timedelta
now = datetime.now()
format_relative_date(now - timedelta(minutes=30)) # "30 minutes ago"
format_relative_date(now - timedelta(hours=2)) # "2 hours ago"
format_relative_date(now - timedelta(days=3)) # "3 days ago"
format_relative_date(now + timedelta(days=1)) # "Tomorrow"
Converting to a specific timezone
from dttools import to_timezone
from datetime import datetime, timezone
utc_now = datetime.now(timezone.utc)
to_timezone(utc_now, "America/New_York")
Naive datetimes are treated as UTC.
License
MIT - see LICENSE.
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 dttools-0.2.0.tar.gz.
File metadata
- Download URL: dttools-0.2.0.tar.gz
- Upload date:
- Size: 3.4 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8cb9a691a6e8072e289779f7318e26d80b92854f557d22319d20f216cebf9139
|
|
| MD5 |
c4f0aa776c1a924a7bb69c3f06e62145
|
|
| BLAKE2b-256 |
e32218ff5e8d3ca52794c0c01d1e7abf55fbc11d46c29cc24e4f6ed1b3ef5196
|
File details
Details for the file dttools-0.2.0-py3-none-any.whl.
File metadata
- Download URL: dttools-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.1 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0a16b7bdfc69aa5b46da49339dab292ef9abd9f2fded6fabab6073fa0e626fea
|
|
| MD5 |
d882beba09d28042636b2f43123696ac
|
|
| BLAKE2b-256 |
db4c3a49d7a72bb57f85ce3c008a7efb1e83e81a36791944282357e1dbac4704
|