Hi Community!
I need to generate a output based on a startdate and enddate field.
Given:
{
"id": "20738",
"startdate": "2023-05-01",
"enddate": "2023-05-10"
}
Output should be like:
{
"ref_id": "20738",
"day": "2023-05-01",
"hours": "8"
},
{
"ref_id": "20738",
"day": "2023-05-02",
"hours": "8"
},
...
{
"ref_id": "20738",
"day": "2023-05-10",
"hours": "8"
}
Is there a easy way to “generate” this kind of output without custom javascript functions?
(I have only core-plan available)
To be more specific. I wrote a AWS Lambda function that works well, but as I understand Make.com only offers something like this in Enterprise Plan, is that right?
function getDates(startDate, stopDate) {
var dateArray = new Array();
var currentDate = startDate;
while (currentDate <= stopDate) {
if( currentDate.getDay() > 0 && currentDate.getDay() < 6 ) {
// only push weekdays
dateArray.push(new Date (currentDate));
}
currentDate = new Date(currentDate.setDate(currentDate.getDate()+1));
}
return dateArray;
}
exports.handler = async (event, context) => {
console.log('received:', JSON.stringify(event, null, 2));
if( !event.start_date || !event.end_date ) {
throw new Error('This lambda needs start_date as first parameter and end_date as second parameter!');
}
const startDate = new Date(Date.parse(event.start_date+"T00:00:00"));
const endDate = new Date(Date.parse(event.end_date+"T00:00:00"));
console.log('start_date =', startDate.toISOString());
console.log('end_date =', endDate.toISOString());
return getDates(startDate, endDate);
};