0

In the moment-recur documentation the following statement is made and code is given.

With both a start date and an end date set, you can generate all dates within that range that match the pattern (including the start/end dates).

var recurrence = moment().recur("01/01/2014", "01/07/2014").every(2).days();

// Outputs: ["01/01/2014", "01/03/2014", "01/05/2014", "01/07/2014"]
allDates = recurrence.all("L");

However, when I run the code I get an offset in the array that looks like this:

["01/02/2014", "01/04/2014", "01/06/2014"]

I am curious if i am doing something wrong or if it is a bug in the library.

EDIT

When I create a fresh instance of create-react-app the above error does not happen. However, when i run it in my code for the app I am working on I get the error. To troubleshoot, I placed the above code at the top level app.js file to see if the problem still occurs. It does. Below is a screen shot.

enter image description here

William
  • 4,422
  • 17
  • 55
  • 108
  • I've just tried `moment@2.27.0` and `moment-recur@1.0.7` and I'm getting the correct output in `node 14.9.0` – codemax Sep 10 '20 at 04:53
  • I ran a version of the above code in a fresh create-react-app instance it it works fine. When I run it in a preexisting code base of mine I get the offset. If I create a fresh component and import moment and moment-recurr and run the example in my pre-existing code base I still get the error. . I am not sure what it is but I'll leave the post up in case it's not just an issue with my code. – William Sep 10 '20 at 21:18
  • Have you tried using an `iso string` or string with format as seen [here](https://github.com/moment/moment/issues/1407)? – codemax Sep 11 '20 at 00:27
  • @ codemax it still starts at an offset – William Sep 11 '20 at 03:05

0 Answers0