首页 > 解决方案 > 为将来的付款创建日期数组

问题描述

我有 3 个日期:现在日期 = 11/7/2018

开始日期 = 2018 年 11 月 14 日

结束日期 = 2019 年 11 月 13 日

每 3 个月付款一次。如果付款类型是“预付款”,则租金应在 14 日到期。

进步

Array = [8,89,92,92]

如果付款类型 = '欠款',则租金应在 13 日到期。

由于开始日期为 11/14,因此付款日期为 2/13/2019、5/13/2019、8/13/2019 和 11/13/2019。

例子

 Array = [99,88,91,91]

我需要在当前日期和第一个付款日期之间创建一个天数数组。我尝试了什么:

const start = "11/14/2018";
const end = "05/13/2021 ";

const dates = [];

const mstart = moment(start, "MM/DD/YYYY");
const mend = moment(end, "MM/DD/YYYY");


    for (var i = 0; mstart <= mend; i++) {
    if (selectedPayType === "A") {
    let Q = mstart.clone();
    mstart.add(3, 'months');
    const daysInMonth = mstart.diff(Q, 'days');
    dates.push(daysInMonth);
    }
        if (selectedPayType === "B") {
     //code goes here....
    }
    console.log(dates);

我对第二部分感到困惑,不知道如何定义。任何帮助表示赞赏。谢谢你。

标签: javascript

解决方案


我通过在日期上加上 3 个月来做到这一点,因为付款总是从现在起 3 个月。

 if (selectedPayType === "B") {
             startDateC.add(3, 'months');
             startDateC.subtract(1,'days');
             var futureLease = startDateC.diff(presentDateC, 'days');
             array.unshift(futureLease);
             for (var i = 1; i < array.length; i++) {
                 (array[i] += array[i - 1]);
             }
          console.log(array);
         }

推荐阅读