Skip to content

Commit

Permalink
Merge pull request #952 from roonjoot/4.6
Browse files Browse the repository at this point in the history
sptdate business days duration
  • Loading branch information
remkonoteboom committed Oct 17, 2018
2 parents d958e3a + bace83e commit 2922298
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions src/pyasm/common/spt_date.py 100644 → 100755
Expand Up @@ -17,7 +17,7 @@
from datetime import datetime, timedelta
from dateutil import parser
from dateutil.tz import *

from dateutil.rrule import DAILY, rrule, MO, TU, WE, TH, FR

TZLOCAL = tzlocal()
TZUTC = tzutc()
Expand Down Expand Up @@ -151,6 +151,23 @@ def subtract_business_days(cls, from_date, sub_days, holidays=[]):
subtract_business_days = classmethod(subtract_business_days)


def get_business_days_duration(cls, start_date, end_date):

days = rrule(DAILY, dtstart=start_date + timedelta(days=1), until=end_date - timedelta(days=1), byweekday=(MO,TU,WE,TH,FR))

if days.count():
first_day_minute = float(start_date.minute / 60)
end_day_minute = float(end_date.minute / 60)

first_day = float((23 - (start_date.hour + first_day_minute)) / 23.0)
last_day = float((end_date.hour + end_day_minute) / 23.0)

return days.count() + first_day + last_day
else:
return (end_date - start_date).total_seconds() / (60 * 60 * 24)

get_business_days_duration = classmethod(get_business_days_duration)


def convert_to_local(cls, date):
'''convert a time to local time with timezone'''
Expand Down Expand Up @@ -393,9 +410,12 @@ def get_time_ago(cls, date, convert=False, start=None):
if __name__ == '__main__':


date = SPTDate.now() - timedelta(minutes=500.23)
date1 = SPTDate.now()
date2 = SPTDate.now()

#print("Date 1 :" , date1 , " Date 2: ", date2)

print SPTDate.get_time_ago(date)
#print(SPTDate.get_business_days_duration(date1, date2))



Expand Down

0 comments on commit 2922298

Please sign in to comment.