Просмотр исходного кода

测试代码用的文件,可以执行

lrf402788946 3 лет назад
Родитель
Сommit
6ad28fd16a
1 измененных файлов с 43 добавлено и 0 удалено
  1. 43 0
      test/test.js

+ 43 - 0
test/test.js

@@ -0,0 +1,43 @@
+'use strict';
+
+const moment = require('moment');
+const _ = require('lodash');
+
+describe('test/test.js', () => {
+  const create_date = '2020-05-18';
+  const limitMonth = 3;
+  const today = '2022-03-19';
+  // 取专利日期
+  const month = moment(create_date).format('MM-DD');
+  // // 取得当前年份
+  const nowYear = moment().format('YYYY');
+  // // 当前年份+一年
+  const afterYear = moment(nowYear).add(1, 'year').format('YYYY');
+  // // 开始时间(先组合日期,减去三个月)
+  const nowDate = afterYear + '-' + month;
+  const start = moment(nowDate).subtract(limitMonth, 'months').format('YYYY-MM-DD');
+  // 结束时间
+  const end = afterYear + '-' + month;
+  const r = moment(today).isBetween(start, end, null, '[]');
+  console.log(`${start} - ${end}`);
+  console.log(r);
+  if (r) {
+    // 结束日期 和 今天 差的天数
+    const day = moment(end).diff(moment(today), 'days');
+    console.log(`今天和最后一天相差天数:${day}`);
+    // 是否发送的变量
+    let dr = false;
+    if (moment().format('YYYY-MM-DD') === start) {
+      // 第一天发送
+      dr = true;
+    } else {
+      // 差10天就发
+      const dur = 10;
+      // 判断是不是整数.整数就发送
+      dr = _.isInteger(_.floor(_.divide(day, dur)));
+    }
+
+
+  }
+
+});