1

I'm building a calendar application where users can save events that recur.

After a lot of research I've chosen to use the moment-recur plugin to the moment.js library to save the dates of recurring events in the database.

My issue is: users in my application will frequently wish to set an event to repeat at the end of a financial quarter.

In the UK these are 31st March, 30th June, 30th September and 31st December.

I can't work out a way to implement this functionality. If I set the recurrence to be '3 months' like this:

let recurring = moment(date).recur().every(3, 'months');

If the begin date is 31/03/2016 then it will skip June altogether as there are only 30 days in June.

If the begin date is 30/06/2016 then it won't work for the quarters that end on the 31st.

Any advice is much appreciated!

Sean
  • 2,609
  • 1
  • 18
  • 34
  • 1
    Maybe generating 1st April, July, etc. and subtracting one day would be easier? – barbsan Feb 14 '17 at 12:50
  • Hey, thanks for the reply! That actually makes sense. In the end I decided to use the RRule.js package because it's more comprehensive than moment-recur but your solution would have worked! – Sean Feb 15 '17 at 14:53

1 Answers1

2

you can simply get the current quarter and by keep adding number of quarters like 1,2,3 you will get subsequent quarters.

moment().endOf('quarter').startOf('day');
moment().add(1, 'quarter').endOf('quarter').startOf('day');
moment().add(2, 'quarter').endOf('quarter').startOf('day');
moment().add(3, 'quarter').endOf('quarter').startOf('day');
MGA
  • 511
  • 2
  • 11