jkbrzt / rrule

JavaScript library for working with recurrence rules for calendar dates as defined in the iCalendar RFC and more.
https://jkbrzt.github.io/rrule
Other
3.34k stars 513 forks source link

can we set / see previous dates to recurring rules when using rrule? #188

Closed gstlouisgit closed 6 years ago

gstlouisgit commented 6 years ago

I'm using rrule to define the rrule so I can iterate through it and add to a calendar. If I use for instance on today's dated post 'FREQ=YEARLY;BYMONTH=12;BYMONTHDAY=27' in rule.between(new Date(date.getFullYear() - 1, 1, 1), new Date(date.getFullYear() + 1, 12, 31))

I get [Wed Dec 27 2017 09:45:06 GMT-0500 (EST), Thu Dec 27 2018 09:45:06 GMT-0500 (EST)] which is great! But for a calendar view I would need to add on previous dates, so that way recurring yearly, monthly, daily looks good on a calendar. What is my best approach to do this? Can rrule do this?

thanks

espen commented 6 years ago

rule.all() ? See https://github.com/jakubroztocil/rrule/blob/master/README.md

jorroll commented 6 years ago

To clarify, and someone correct me if I'm wrong, but I think rule.all() generates dates starting from DTSTART and going forwards in time. I think the OP is asking how to generate dates going backwards in time. The answer to that, I think, is you'd need to change the DTSTART to be something in the past. If you are working with a calendar application, you're probably passing in the current datetime to DTSTART, which won't work. Also note, that if you don't provide a dtstart option when creating an RRule(), then new Date() is used (i.e. the current datetime).