javascript - 为将来的付款创建日期数组
问题描述
我有 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);
我对第二部分感到困惑,不知道如何定义。任何帮助表示赞赏。谢谢你。
解决方案
我通过在日期上加上 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);
}
推荐阅读
- git - Husky v5 不创建 Git 钩子
- javascript - 如何更改本机反应中的每个图标名称
- c++ - 如何有效地在 googletest 中组织单元测试
- apache-spark - PySpark 数据框条件按窗口/滞后
- google-chrome - 查看源代码开始显示1行中的所有代码,如何更改?
- demandware - 如何使用 SFRA 创建站点,但名称和 ID 将是我的自定义名称和 ID
- css - 如何使我的 :active 伪元素工作?
- python - AI 100 测试人脸检测 API 练习
- qt - 如何在其他类中获取应用程序的QML引擎
- r - 如何用循环的输出覆盖循环中的列列表?