In my JSON array, specifically the 5th and 6th elements, I have the following data:
[
{
Day: 'Mon',
EndTime: '{ts \'1970-01-01 18:00:00\'}',
StartTime: '{ts \'1970-01-01 16:30:00\'}',
courseName: 'Computer Science 250: Introduction to Website Design',
Credits: '4'
},
{
Day: 'Mon',
EndTime: '{ts \'1970-01-01 18:30:00\'}',
StartTime: '{ts \'1970-01-01 17:30:00\'}',
courseName: 'Math 220: Differential Equations',
Credits: '3'
}
]
The objects in the array are sorted based on the 'EndTime' values. I am encountering an issue when checking if the end time of the previous object (at i - 1 which is 18:00:00) falls between the start and end time of the next object (at i which ranges from 17:30:00 to 18:30:00), where instead of getting true from the isBetween method, it returns false.
I need help identifying and fixing the mistake in my code. Can you pinpoint what I'm doing wrong?
Below is the snippet of my code for reference:
for(let i = 1; i < monday.length-1; i++) {
const year = '1970-01-01';
const format = 'DD/MM/YYYY hh:mm:ss a';
var next_endtime = monday[i].EndTime.substr(16, 8);
var next_starttime = monday[i].StartTime.substr(16, 8);
var prev_endtime = monday[i-1].EndTime.substr(16, 8);
var plesson_e = moment(year + 'T' + prev_endtime, format),
nlesson_start = moment(year + 'T' + next_starttime, format),
nlesson_end = moment(year + 'T' + next_endtime, format);
var testbool = moment(plesson_e).isBetween(nlesson_start, nlesson_end, 'time');
console.log(testbool);
}