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 juestr
from datetime import date, datetime, timedelta
def working_hours(
date1: str, date2: str, start_time: str, end_time: str, holy: list[str]
) -> int | float:
d1 = datetime.fromisoformat('2000-01-01 ' + start_time)
d2 = datetime.fromisoformat('2000-01-01 ' + end_time)
work_minutes = (d2 - d1).seconds // 60
holidays = set(map(date.fromisoformat, holy))
current = date.fromisoformat(date1)
end = date.fromisoformat(date2)
one_day = timedelta(days=1)
days = 0
while current <= end:
days += current.weekday() < 5 and current not in holidays
current += one_day
return int(days * work_minutes * 100 / 60) / 100
April 28, 2023