Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for Working Hours Calculator by eugene100372
from datetime import datetime, date, time, timedelta
def working_hours(
date1: str, date2: str, start_time: str, end_time: str, holy: list[str]
) -> int | float:
date1, date2=map(date.fromisoformat,(date1,date2))
time1, time2=map(time.fromisoformat,(start_time,end_time))
holy={date.fromisoformat(el) for el in holy}
shift=(datetime.combine(date1,time2)-
datetime.combine(date1,time1)).total_seconds()
res=0
while date1<=date2:
if date1 not in holy and date1.weekday() not in (5,6): res+=shift
date1=date1+timedelta(days=1)
return round(res/3600,2)
March 20, 2025
Comments: