Calculates the business time between two datetimes.
Project description
Work Time Calculator
Small tool to calculate the exact business time between two datetimes.
I wasn't happy with the existing tools for their performance, while others only counted the business days. This was built with the goal of being as efficient as possible, easy to use and flexible.
Features
- Fast! Calculations done in constant time
- Multiple ways to define working hours
- Specific schedule for each day of the week
- Can consider holidays
Install
pip install worktimecalc
Quick example
Just create a calculator and call it to get the difference:
from worktimecalc.calc import WorkTimeCalculator
calc = WorkTimeCalculator(9, 18, 'mon tue thu fri sat')
delta = calc("2050-02-10T10:30:00", "2050-03-10T18:15:00")
print(delta.seconds) # 675000.0
print(delta.as_dhms) # {'days': 7, 'hours': 19, 'minutes': 30, 'seconds': 0}
print(delta.as_hms) # {'hours': 187, 'minutes': 30, 'seconds': 0}
Holidays
Pass it a list of datetime.date objects:
holidays = [(2023, 1, 1), (2023, 5, 1), (2023, 11, 1), (2023, 12, 25)]
holidays = [datetime.date(*d) for d in CHILE_HOLIDAYS]
calc = WorkTimeCalculator(10, 18, holidays=holidays)
Constructor examples
calc = WorkTimeCalculator(8, 15)
calc = WorkTimeCalculator(8, 15, '1100100')
calc = WorkTimeCalculator(8, 15, 'sat tue thu mon sun')
calc = WorkTimeCalculator("08:30", "18:30")
calc = WorkTimeCalculator(9, "17:45")
calc = WorkTimeCalculator(datetime.time(8, 30), datetime.time(18, 30))
calc = WorkTimeCalculator(detail=[(8, 16), (8, 16), (8, 16), (8, 16), (8, 10), None, None])
calc = WorkTimeCalculator(detail=[(8, "16:30"), ("17:15", 20), None, None, None, None, None])
When in doubt simply check the descriptions for each argument.
To do
- Overnight shifts (spanning two days)
- Small performance improvements (minmaxing)
- Allow passing holidays as list of tuples
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 worktimecalc-0.1.4.tar.gz.
File metadata
- Download URL: worktimecalc-0.1.4.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d8e2643848d8846bf55d45ebab565bae8864aa73b9f1c88b1b554990a9f98871
|
|
| MD5 |
3fa6e3aaad8e6cb90e429330727fb1eb
|
|
| BLAKE2b-256 |
f99cbcb68069c476c827c2b4493f20e6f5b5eac3bfef56fe9b399fec5e35dbe5
|
File details
Details for the file worktimecalc-0.1.4-py3-none-any.whl.
File metadata
- Download URL: worktimecalc-0.1.4-py3-none-any.whl
- Upload date:
- Size: 7.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5910851afb0fd857e550fd475970979e8ff681249062c19259d88ad1f74e5501
|
|
| MD5 |
8ef5ad6ae3874278ebfbf6b73f175fdc
|
|
| BLAKE2b-256 |
670adabacf06ae5aab163cb72dfbafa73c8af41a62aa6badcabbb86efd4a6e16
|