Skip to main content

Business_Duration

Calculates business duration in days, hours, minutes and seconds by excluding weekends, public holidays and non-business hours

How to install the package

pip install business-duration

Example 1

from business_duration import businessDuration
import pandas as pd
import holidays as pyholidays
from datetime import time

#Start date must be in standard python datetime format
start_date = pd.to_datetime('2017-07-01 02:02:00')

#Start date must be in standard python datetime format
end_date = pd.to_datetime('2017-07-07 04:48:00')

#Business open hour must be in standard python time format-Hour,Min,Sec
biz_open_time=time(7,0,0)

#Business close hour must be in standard python time format-Hour,Min,Sec
biz_close_time=time(17,0,0)

#US public holidays
US_holiday_list = pyholidays.US(state='CA')

#Business duration can be 'day', 'hour', 'min', 'sec'
unit_hour='hour'

#Printing output
print(businessDuration(startdate=start_date,enddate=end_date,starttime=biz_open_time,endtime=biz_close_time,holidaylist=US_holiday_list,unit=unit_hour))

#Result
#30.0

#Result is 30 hours because July 1st, 2nd are weekends and 4th is US public holiday. So 3 days remains with 10 business hours per day. 3 days*10 hours = 30 Hours

Example 2

from business_duration import businessDuration
from datetime import datetime

start_date = datetime.strptime("2018-01-01","%Y-%m-%d").date()
end_date = datetime.strptime("2018-03-31","%Y-%m-%d").date()

print(businessDuration(startdate=start_date,enddate=end_date,unit='day'))

#Result
65.0

Example 3

from business_duration import businessDuration
import pandas as pd
import holidays as pyholidays
from datetime import time,datetime

#Reading input file
inputdata = pd.read_excel('Sample.xls')

#Converting to standard Python datetime format
inputdata.sys_created_on=pd.to_datetime(inputdata.sys_created_on,format='%Y-%m-%d %H:%M:%S')
inputdata.resolved_at=pd.to_datetime(inputdata.resolved_at,format='%Y-%m-%d %H:%M:%S')

#Business open hour
biz_open_time = time(8,0,0)

#Business close time
biz_close_time = time(17,0,0)

#Weekend list. 5-Sat, 6-Sun
weekend_list = [5,6]

#Custom US holidays
US_holiday_list = {datetime(2018,1,1).date():"New Year's Day",datetime(2018,5,28).date():"Memorial Day",datetime(2018,7,4).date():"Independence Day",datetime(2018,9,3).date():"Labor Day",datetime(2018,11,22).date():"Thanksgiving",datetime(2018,12,25).date():"Christmas Day"}

#Business duration 'day','hour','min','sec'
unit_hour='hour'

#Applying the function to entire dataframe
from itertools import repeat
inputdata['Biz_Hour'] = list(map(businessDuration,inputdata.sys_created_on,inputdata.resolved_at,repeat(biz_open_time),repeat(biz_close_time),repeat(weekend_list),repeat(US_holiday_list),repeat(unit_hour)))

Metadata

Release files for business-duration 0.68

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for business-duration 0.68
File Size Uploaded
business_duration-0.68.tar.gz 3.6 kB Details

Release files / business_duration-0.68.tar.gz

Download URL business_duration-0.68.tar.gz
Size 3.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8d5dc0ef97c2e3b80cb30275e0b299b0e29c4a155ee2150b89d155ff75ab3068
BLAKE2b-256 checksum
How to use checksums
ea2482a24eac640844c4bb3015e144055b940089ea8ef822283d9274daf569dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.0

Release history Release notifications | RSS feed

This release

0.68 This release

1 release file

0.67

1 release file

0.66

1 release file

0.65

1 release file

0.64

1 release file

0.63

1 release file

0.62

1 release file

0.61

1 release file

0.6

1 release file

0.5

1 release file

0.4

1 release file

0.3

1 release file

0.2

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page