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
=========
.. code:: python
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
=========
.. code:: python
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
=========
.. code:: python
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)))
Raw data
{
"_id": null,
"home_page": "https://github.com/gnaneshwar441/Business_Duration",
"name": "business-duration",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "business, duration, time, hour, day, working",
"author": "Gnaneshwar G",
"author_email": "gnaneshwar441@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/ca/53/93be9b28e328e9aeefe07b290950cbd37f069f6edcbd70a098104a8124e0/business_duration-0.67.tar.gz",
"platform": null,
"description": "Business\\_Duration\r\n==================\r\n\r\nCalculates business duration in days, hours, minutes and seconds by\r\nexcluding weekends, public holidays and non-business hours\r\n\r\nHow to install the package\r\n==========================\r\n\r\npip install business-duration\r\n\r\nExample 1\r\n=========\r\n\r\n.. code:: python\r\n\r\n from business_duration import businessDuration\r\n import pandas as pd\r\n import holidays as pyholidays\r\n from datetime import time\r\n\r\n #Start date must be in standard python datetime format\r\n start_date = pd.to_datetime('2017-07-01 02:02:00')\r\n\r\n #Start date must be in standard python datetime format\r\n end_date = pd.to_datetime('2017-07-07 04:48:00')\r\n\r\n #Business open hour must be in standard python time format-Hour,Min,Sec\r\n biz_open_time=time(7,0,0)\r\n\r\n #Business close hour must be in standard python time format-Hour,Min,Sec\r\n biz_close_time=time(17,0,0)\r\n\r\n #US public holidays\r\n US_holiday_list = pyholidays.US(state='CA')\r\n\r\n #Business duration can be 'day', 'hour', 'min', 'sec'\r\n unit_hour='hour'\r\n\r\n #Printing output\r\n print(businessDuration(startdate=start_date,enddate=end_date,starttime=biz_open_time,endtime=biz_close_time,holidaylist=US_holiday_list,unit=unit_hour))\r\n\r\n #Result\r\n #30.0\r\n\r\n #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\r\n\r\nExample 2\r\n=========\r\n\r\n.. code:: python\r\n\r\n from business_duration import businessDuration\r\n from datetime import datetime\r\n\r\n start_date = datetime.strptime(\"2018-01-01\",\"%Y-%m-%d\").date()\r\n end_date = datetime.strptime(\"2018-03-31\",\"%Y-%m-%d\").date()\r\n\r\n print(businessDuration(startdate=start_date,enddate=end_date,unit='day'))\r\n\r\n #Result\r\n 65.0\r\n\r\nExample 3\r\n=========\r\n\r\n.. code:: python\r\n\r\n from business_duration import businessDuration\r\n import pandas as pd\r\n import holidays as pyholidays\r\n from datetime import time,datetime\r\n\r\n #Reading input file\r\n inputdata = pd.read_excel('Sample.xls')\r\n\r\n #Converting to standard Python datetime format\r\n inputdata.sys_created_on=pd.to_datetime(inputdata.sys_created_on,format='%Y-%m-%d %H:%M:%S')\r\n inputdata.resolved_at=pd.to_datetime(inputdata.resolved_at,format='%Y-%m-%d %H:%M:%S')\r\n\r\n #Business open hour\r\n biz_open_time = time(8,0,0)\r\n\r\n #Business close time\r\n biz_close_time = time(17,0,0)\r\n\r\n #Weekend list. 5-Sat, 6-Sun\r\n weekend_list = [5,6]\r\n\r\n #Custom US holidays\r\n 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\"}\r\n\r\n #Business duration 'day','hour','min','sec'\r\n unit_hour='hour'\r\n\r\n #Applying the function to entire dataframe\r\n from itertools import repeat\r\n 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)))\r\n\r\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Calculates business duration in days, hours, minutes and seconds by excluding weekends, public holidays and non-business hours",
"version": "0.67",
"project_urls": {
"Homepage": "https://github.com/gnaneshwar441/Business_Duration"
},
"split_keywords": [
"business",
" duration",
" time",
" hour",
" day",
" working"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ca5393be9b28e328e9aeefe07b290950cbd37f069f6edcbd70a098104a8124e0",
"md5": "c9fc85360209b7c723a5eef66d715495",
"sha256": "bed03b56d2823ea1944e016a6b0160f1cf7722f052403700af59bcf77bb1fbff"
},
"downloads": -1,
"filename": "business_duration-0.67.tar.gz",
"has_sig": false,
"md5_digest": "c9fc85360209b7c723a5eef66d715495",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 3608,
"upload_time": "2024-05-13T16:41:05",
"upload_time_iso_8601": "2024-05-13T16:41:05.079952Z",
"url": "https://files.pythonhosted.org/packages/ca/53/93be9b28e328e9aeefe07b290950cbd37f069f6edcbd70a098104a8124e0/business_duration-0.67.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-13 16:41:05",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "gnaneshwar441",
"github_project": "Business_Duration",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "business-duration"
}