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 kdim
from datetime import datetime, timedelta
def working_hours(date1: str, date2: str, start_time: str, end_time: str, holy: list[str]) -> int | float:
dt = lambda x: datetime.strptime(x, "%Y-%m-%d")
hs = lambda x: datetime.strptime(x, "%H:%M")
td = lambda x: dt(date1) + timedelta(days=x)
days = (dt(date2) - dt(date1)).days + 1
days = {td(i) for i in range(days) if td(i).weekday() < 5} - {dt(i) for i in holy}
hours = (hs(end_time) - hs(start_time)).total_seconds() / 3600
return round(len(days) * hours, 2)
April 22, 2023
Comments: