Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Some useful modules solution in 3rd party category for Working Hours Calculator by Nocturne13
from datetime import date, time, datetime, timedelta
import numpy as np
def working_hours(
date1: str, date2: str, start_time: str, end_time: str, holy: list[str]
) :
# your code here
d1 = date.fromisoformat(date1)
d2 = date.fromisoformat(date2)
diff = np.busday_count(d1, d2+timedelta(1))
t1 = time.fromisoformat(start_time)
t2 = time.fromisoformat(end_time)
duration = datetime.combine(date.min, t2) - datetime.combine(date.min, t1)
if str(duration.seconds/3600).endswith("0"):
return (diff - len(holy)) * int(duration.seconds/3600)
elif not str(duration.seconds/3600).endswith("0"):
return round((diff - len(holy)) * (duration.seconds / 3600), 2)
print("Example:")
print(working_hours("2023-03-01", "2023-03-01", "09:00", "17:00", []))
# These "asserts" are used for self-checking
assert working_hours("2023-03-01", "2023-03-01", "09:00", "17:00", []) == 8
assert working_hours("2023-03-01", "2023-03-02", "09:00", "17:00", []) == 16
assert working_hours("2023-03-01", "2023-03-03", "09:00", "17:00", ["2023-03-01"]) == 16
assert (
working_hours("2023-03-01", "2023-03-05", "08:45", "17:10", ["2023-03-03"]) == 16.83
)
print("The mission is done! Click 'Check Solution' to earn rewards!")
April 6, 2023
Comments: