Created
December 4, 2021 01:57
-
-
Save guilhermelirio/955f3f5bec51a57b540898d3b1d3e48d to your computer and use it in GitHub Desktop.
Create array of dates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const allDays = [0, 3, 5]; | |
function formatToPush(dt_inicio, dt_final, dia, horas) { | |
let start = moment(dt_inicio); | |
let end = moment(dt_final); | |
let result = []; | |
let datas = []; | |
let current = start.clone(); | |
//console.log(current.day(dia).format('YYYY-MM-DD'), current.day(dia).isSame(end)) | |
if ((current.day(dia).isSameOrAfter(start)) || (current.day(dia).isSameOrAfter(end)) || (current.day(7 + dia).isSameOrBefore(end))) { | |
result.push(current.clone()); | |
} | |
result.map(m => { | |
horas.map(h => { | |
m.set({ hour: h.split(':')[0], minute: h.split(':')[1], second: 0, millisecond: 0 }); | |
datas.push(m.format('YYYY-MM-DD HH:mm:ss [GMT]ZZ')) | |
}) | |
}); | |
return datas; | |
} | |
let final = []; | |
for (let i in allDays) { | |
final.push(...formatToPush('2021-12-01', '2021-12-10', allDays[i], ["10:00", "16:00", "22:30"])) | |
} | |
console.log(final) | |
//[ | |
// '2021-12-05 10:00:00 GMT-0300', | |
// '2021-12-05 16:00:00 GMT-0300', | |
// '2021-12-05 22:30:00 GMT-0300', | |
// '2021-12-01 10:00:00 GMT-0300', | |
// '2021-12-01 16:00:00 GMT-0300', | |
// '2021-12-01 22:30:00 GMT-0300', | |
// '2021-12-03 10:00:00 GMT-0300', | |
// '2021-12-03 16:00:00 GMT-0300', | |
// '2021-12-03 22:30:00 GMT-0300' | |
// ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment