Node.js:规则未产生预期的输出

问题描述

我有以下代码,用于使用rruleluxon包从rrule输出时间。我对他们的输出有问题。我确定这与夏时制有关,但无法弄清楚到底是什么引起了该问题:

/* For Feb. events,const event = {
  dateTime: '2020-02-01T15:00:00Z',timeZone: 'Europe/London',}

*/

// Using Apr. events
const event = { 
  dateTime: '2020-04-08T15:00:00+01:00',}

const rrulesstring = event.recurrence.join('\n');
console.log(rrulesstring);
// Outputs: `RRULE:FREQ=WEEKLY;WKST=TU`

const rrules = rrulestr(rrulesstring,{
  dtstart: DateTime.fromISO(event.dateTime).toUTC().toJSDate(),});

const lowerLimit = Now.minus({ month: 12 }).toJSDate();
const upperLimit = Now.plus({ month: 12 }).toJSDate();
const dates = rrules.between(lowerLimit,upperLimit);

const eventStart = DateTime.fromISO(event.dateTime);

const mappedDates = dates.map(date => {
  const start = DateTime.fromJSDate(date);
  const end = start.plus({ hour: 2 });

  return {
    start: start.toJSDate(),end: end.toJSDate(),};
});

console.log(mappedDates);
/* 
For Feb. events,outputs:
[
  { start: 2020-02-05T15:00:00.000Z,end: 2020-02-05T16:00:00.000Z },{ start: 2020-02-12T15:00:00.000Z,end: 2020-02-12T16:00:00.000Z },{ start: 2020-02-19T15:00:00.000Z,end: 2020-02-19T16:00:00.000Z },{ start: 2020-02-26T15:00:00.000Z,end: 2020-02-26T16:00:00.000Z },{ start: 2020-03-04T15:00:00.000Z,end: 2020-03-04T16:00:00.000Z },{ start: 2020-03-11T15:00:00.000Z,end: 2020-03-11T16:00:00.000Z },{ start: 2020-03-18T15:00:00.000Z,end: 2020-03-18T16:00:00.000Z },{ start: 2020-03-25T15:00:00.000Z,end: 2020-03-25T16:00:00.000Z }
]

For Apr. events,outputs:
[
  { start: 2020-04-08T14:00:00.000Z,end: 2020-04-08T15:00:00.000Z },{ start: 2020-04-15T14:00:00.000Z,end: 2020-04-15T15:00:00.000Z },{ start: 2020-04-22T14:00:00.000Z,end: 2020-04-22T15:00:00.000Z },{ start: 2020-04-29T14:00:00.000Z,end: 2020-04-29T15:00:00.000Z },{ start: 2020-05-06T14:00:00.000Z,end: 2020-05-06T15:00:00.000Z },{ start: 2020-05-13T14:00:00.000Z,end: 2020-05-13T15:00:00.000Z },]

Note the hours difference!
*/

如何防止这两个小时输出不同?当然,UTC与DST无关吗?我想念什么?与此类似,请注意,我曾经问过一个关于将rruletzid here一起使用的问题,但我想知道是否还有其他方法可以解决此问题。

我目前的hacky想法是使用.replace(/[+-][0-9]{2}:[0-9]{2}$/,'')(或者用Z来代替偏移量),但我真的想把它作为最后的选择!

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)