我在节点中使用“rrule.js”库来解析我的 RRule。我想知道当天是否与规则日相同。它适用于大多数情况,但不是全部。我也使用 moment.js 进行比较。问题出在“rule.after()”中。它应该包括当天,但它没有。
function checkIfToday(rruleStr){
var RRule = require('rrule').RRule;
var moment = require('moment');
var rule = RRule.fromString(rruleStr);
// Convert all dates into UTC before comparison
var todayutc = moment().utc(); // today in UTC
var nextOccurrence = rule.after(todayutc,inc=true); // next rule date including today
var nextOccurutc = moment(nextOccurrence).utc(); // convert today into utc
var match = moment(nextOccurutc).isSame(todayutc, 'day'); // check if 'DAY' is same
return match;
}
知道什么是最好的方法。
谢谢。