Supongamos que hay dos fechas: 2022-01-10 y 2022-08-20.
El usuario puede escribir un día de un mes cuando una acción debe ejecutarse repetidamente una vez al mes entre estas fechas.
Entonces, si el usuario escribe "25", la acción debe ejecutarse 7 veces, porque la fecha de finalización está fuera de rango.
¿Cómo obtener tal resultado usando luxon en JavaScript? Necesito tener una cantidad de fechas coincidentes O (eso sería aún mejor) una lista de estas fechas.
Otro ejemplo:
Aporte:
Día de un mes: 5
Fecha de inicio: 2022-07-08
Fecha de finalización: 2022-09-05
Rendimiento esperado:
2022-08-05
2022-09-05
Gracias por adelantado.
Un poco raro, pero esto debería llevarte por un camino decente...
const startDate = luxon.DateTime.utc(2022, 1, 5, 0, 0, 0, 0) const endDate = luxon.DateTime.utc(2022, 6, 5, 0, 0, 0, 0) const diff = endDate.diff(startDate, ["months"]) // we get a diff of `5` here, let's generate the date map next console.log(diff.toObject()) const possibleDates = [] const dayOfMonthInput = 2 const targetDateByInput = luxon.DateTime.utc(2022, 1, dayOfMonthInput, 0, 0, 0, 0) for ( let i = 0,maybeDate=targetDateByInput; i <= diff.months; i++, maybeDate = targetDateByInput.plus({ months: i })) { // is maybeDate valid after START date? if (maybeDate.startOf('day') > startDate.startOf('day')) { // is maybeDate valid BEFORE end date? if (maybeDate.startOf('day') < endDate.startOf('day')) { // add to collection possibleDates.push(maybeDate) } } } // output possible dates console.log(possibleDates) <script src="https://cdn.jsdelivr.net/npm/luxon@1.25.0/build/global/luxon.min.js"></script>