There is a datetime received from my api as 2018-09-01T00:00:00.000Z
, referred to as frame.scandate
.
Another date is generated within the program as 2018-09
, simply known as scandate
. These examples can represent any year/month combination.
In my code:
this.allStations.forEach(station => {
station.frames.forEach(frame => {
if(moment(frame.scandate).isSame(moment(scandate), 'month')){
total+=frame.framesTotal;
}
})
This compares the previous frame.scandate
with the current scandate
.
For instance:
scandate = '2018-09';
frame.scandate = '2018-09-01T00:00:00.000Z';
console.log(moment(scandate).format('YYYY-MM'));
console.log(moment(frame.scandate).format('YYYY-MM'));
The output will be:
2018-09
2018-08
By modifying the code in this way, the issue was resolved:
this.allStations.forEach(station => {
station.frames.forEach(frame => {
if(moment(frame.scandate).add(1, 'minute').isSame(moment(scandate), 'month')){
total+=frame.framesTotal;
}
})
The key change being .add(1, 'minute')
.
Is this discrepancy due to the time value of 00:00:00Z
in the frame.scandate
? Any insight on this would be appreciated.