I am faced with a JSON structure like the one below:
var meetings = [
{
id: '1',
start_time: "2020-11-15T08:30:00+00:00",
end_time: "2020-11-15T14:15:00+00:00"
},
{
id: '2',
start_time: "2020-11-15T19:30:00+00:00",
end_time: "2020-11-15T20:30:00+00:00"
},
];
The two meetings are scheduled as follows: first from 08:30 to 14:15, and second from 19:30 to 20:30
In a day, there are 24 available hours for work, which means:
start_time = '00:00:00';
end_time = '23:59:00';
However, the required format should be:
var start_time = '2020-11-15T00:00:00+00:00';
var end_time = '2020-11-15T23:59:00+00:00';
How can I calculate the available hours considering the already scheduled meetings? For example, if the first meeting is from 08:30 to 14:15 and the second is from 19:30 to 20:30, the resulting JSON with available hours would be:
[
{
start_time:'2020-11-15T00:00:00+00:00',
end_time:'2020-11-15T08:30:00+00:00'
},
{
start_time:'2020-11-15T14:15:00+00:00',
end_time:'2020-11-15T19:30:00+00:00'
},
{
start_time:'2020-11-15T20:30:00+00:00',
end_time:'2020-11-15T23:59:00+00:00'
}
]