I'm trying to fetch stripe charges for yesterday and the current month depending on the switch statement. However, I think I've got something off. I don't think I'm constructing my date objects as they need to be. This is in JavaScript:
const getEpochValueForTimeRangeStart = function getEpochValueForTimeRangeStart(range) {
const now = new Date();
let returnValue;
switch(range) {
case 'ALL':
returnValue = new Date(0);
break;
case 'TODAY':
returnValue = new Date(now.getFullYear(), now.getMonth(), now.getDate(), 0, 0, 0, 0);
break;
case 'YESTERDAY':
returnValue = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1, 0, 0, 0, 0);
break;
case 'MONTH':
returnValue = new Date(now.getFullYear(), now.getMonth() - 1, 0, 0, 0, 0);
break;
}
return Math.floor(returnValue.getTime() / 1000);
}
The 'ALL' and 'TODAY' ones work as expected, but the other two ('YESTERDAY' and 'MONTH') don't work as expected. What am I doing wrong here?