Programming Kata – D-1 Processing
I've encountered this problem in a previous job and thought it can be interesting for practice.
Description
Create a program or function the receives a Date (or gets the current one) and prints/returns a time range dependent on which week-day. The range should begin at the start of the previous work-day and end at the beginning of the received date (not inclusive), is such that:
Week-day | Result |
---|---|
Sunday | null /empty /[] |
Monday | [Previous Friday 00:00 – Previous Sunday 24:00) |
Tuesday | [Previous Monday 00:00 – 24:00) |
Wednesday | [Previous Tuesday 00:00 – 24:00) |
Thursday | [Previous Wednesday 00:00 – 24:00) |
Friday | [Previous Thursday 00:00 – 24:00) |
Saturday | null /empty /[] |
(The [)
represents a closed-open interval)
Extension
Connect to a database or service to retrieve a list of holidays, and treat them the same as weekend days.