Skip to main content

A simple library for common date and time manipulations

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dttools-1.0.0.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

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

dttools-1.0.0-py3-none-any.whl (4.1 MB view details)

Uploaded Python 3

File details

Details for the file dttools-1.0.0.tar.gz.

File metadata

  • Download URL: dttools-1.0.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

Hashes for dttools-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ffc2ce3bbba40f0128423bfee7763dfdd5f6f345148d7b2451657047db0902c8
MD5 71f4b80901b57239e8ec255b97eeb865
BLAKE2b-256 e450bfef20a7fda22e70d99494e87834282e456ad50153a7627f6b0627f57728

See more details on using hashes here.

File details

Details for the file dttools-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: dttools-1.0.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

Hashes for dttools-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d8ae58caaeb76c30e660673b7c1534ce7f156d10b24f8d2f090dd56b920714f9
MD5 2dfe8f1a5f75746172b8185512c62b98
BLAKE2b-256 fc48061617edca9a91ebc4d5ad268e9ddcd85df4f581522791152008f5cc1b31

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