Add Business Days to a Date
A delivery estimate needs "N business days from dateIso". Dates are calendar dates YYYY-MM-DD in UTC. Business days are Monday to Friday, excluding any date listed in holidays.
If days is positive, step forward one calendar day at a time and count only business days until days have been counted; return the date you land on. A negative days steps backwards the same way. days = 0 returns dateIso unchanged, even if it is a weekend.
Return the result as YYYY-MM-DD.
Example 1
Input: dateIso = "2024-03-08", days = 1, holidays = [] Output: "2024-03-11" Explanation: Friday plus one business day is Monday.
Example 2
Input: dateIso = "2024-12-24", days = 2, holidays = ["2024-12-25"] Output: "2024-12-27" Explanation: Christmas Day is a holiday, so it is skipped.
Constraints
- Dates are between 1971-01-01 and 2099-12-31
- -1000 <= days <= 1000
- 0 <= holidays.length <= 100
Hint 1
Date.UTC(y, m - 1, d) gives a timestamp; add or subtract 86400000 per day.
Hint 2
getUTCDay() returns 0 for Sunday and 6 for Saturday.
Discussion 0
Join free to post in the discussion.
Good practice for: Backend Developer, Full Stack Developer, Frontend Developer, Data Engineer, Automation Test Engineer, Mobile App Developer
Run checks your code on 3 sample tests. Submit runs all 9 tests, including hidden ones, and earns points. Use console.log to debug. Python's first run can take a few seconds while it starts.