I'm using Day.js library.
I have a list of working days, every day from 10am to 6pm.
Furthermore, I want to insert the appointment date into the list and add it to the duration. but if that sum exceeds 6pm, the next day, the remainder should continue to be added from 10am.
Of course, every Sunday should be skipped.
I want to add to the list appointment date as a starting date:
{ appointmentDate: '2023-01-21T16:00:00-06:00'}
Then to add appointmentDate + duration and display as
{ appointmentDate: '2023-01-25T12:00:00-06:00'}
What is the best way to do something like this, and do you have any examples?
Below is an example of how I would like the list to look:
Request data:
let duration = "20:00:00" // 20 hours
let appointmentDate = '2023-01-21T16:00:00-06:00'
Example of working days:
[
{ startDate: '2023-01-21T10:00:00-06:00'}, //Saturday
{ endDate: '2023-01-21T18:00:00-06:00'},
{ startDate: '2023-01-23T10:00:00-06:00'}, // Monday
{ endDate: '2023-01-23T18:00:00-06:00'},
{ startDate: '2023-01-23T10:00:00-06:00'}, // Tuesday
{ endDate: '2023-01-23T18:00:00-06:00'},
{ startDate: '2023-01-23T010:00:00-06:00'}, // Wednesday
{ endDate: '2023-01-23T218:00:00-06:00'},
{ startDate: '2023-01-23T10:00:00-06:00'}, // Thursday
{ endDate: '2023-01-23T18:00:00-06:00'},
]
Final result:
[
{ startDate: '2023-01-21T10:00:00-06:00'}, //Saturday
{ appointmentDate: '2023-01-21T16:00:00-06:00'}, // appointment start date + 20h
{ endDate: '2023-01-21T18:00:00-06:00'},
{ startDate: '2023-01-23T10:00:00-06:00'}, // Monday
{ endDate: '2023-01-23T18:00:00-06:00'},
{ startDate: '2023-01-24T10:00:00-06:00'}, // Tuesday
{ endDate: '2023-01-24T18:00:00-06:00'},
{ startDate: '2023-01-25T10:00:00-06:00'}, // Wednesday
{ appointmentDate: '2023-01-25T12:00:00-06:00'}, // appointment end date
{ endDate: '2023-01-25T218:00:00-06:00'},
{ startDate: '2023-01-26T10:00:00-06:00'}, // Thursday
{ endDate: '2023-01-26T18:00:00-06:00'},
]