Support for repeating dates and repeat rules is a much needed feature.

Date repeat in Drupal 7

In D7, a date repeat feature was provided by the date_repeat module, part of the date module package.

It worked, but had some problems: All occurrences of a date became field items in a multivalue date field, which means that whenever the loading the host entity, all occurrences are loaded, each row repeating the repeat rule as well (due to the design of field api). This means memory and performance problems once we're talking about many occurrences (think a dayly repeat rule for a few years, which is not that uncommon for some calendar applications).

Status for Drupal 8

I did some first steps towards a D8 solution. It builds upon the daterange field introduced in Drupal 8.2.x-dev.

See https://www.drupal.org/project/date_recur. It would likely have to be adjusted slightly to be included in datetime_extras (though I guess a submodule within datetime_extras would be best anyway).

Architecture

Instead of storing all occurrences in field api, only the start date and the repeat rule is stored in the field. The occurences are stored in a seperate, per-field date_recur cache table. It is currently only used for Views support. When building/viewing a complete entitiy, the occurences are calculated instead. This is likely slower than querying from the cache table so this might change or at least need a performance evaluation for a few scenarios.

Todos / next steps

  • Review architecture (see first comment)
  • Provide UI to create repeat rules in the widget. done.
  • Provide a formatter with options: Show n next occurrences. Show repeat rule in human readable language. partly done, human-readable needs work (no translation support)
  • Write tests
  • Evaluate perfomance of data model and rrule libraries. Possibly use cached occurences in formatter. Maybe also make it possible via a field-level setting to load all or the next / past n occurences upon field loading.
  • Add proper cache tags.

Help, both in form of reviews and in form of development, is much appreciated.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Frando created an issue. See original summary.

Frando’s picture

Issue summary: View changes

A bit more on the architecture:

Currently, the date_recur field extends the daterange field and adds an rrule and a repeat_end column. Possibly, a boolean is_recuring would be good as well (to more easily filter in views between repeating and non-repeating dates).

Upon field creation, a seperate table is added (date_recur__ENTITY_TYPE__FIELD_NAME). When saving repeating field items, all occurrences are calculated (using php-rrule) and for each occurrence a row is added to the table. For non-repeating dates, the date values are added as well.

This table is then made available to views in place of the original field data table (they are switched out). Revision support is not there for now but could be easily added I think. Maybe this should be optional for performance reasons (i.e. make it possible to always only store occurrences of the current revision - this is how it works right now).

Most important missing feature is a UI to create and edit rrules. Maybe some code of D7 date_repeat can be reused. I also stumbled upon https://github.com/superherogeek/rrule-generator-form which could be adapted and integrated, possibly. I think it would be OK to have the RRULE be generated completely client-side via JS and then in PHP just validate that its parseable as an RRULE.

Quite some features are mostly UI (e.g. exclusion, inclusion) as long as the rrule library supports it. I used php-rrule because it is quite simple, this can also be re-evaluated, also possibly for performance.

Frando’s picture

Issue summary: View changes
Frando’s picture

Issue summary: View changes
Frando’s picture

FileSize
1.09 KB

With the attached patch to calendar, recurring dates work in the calendar. Not yet submitting to calendar, first waiting for things to settle down.

Frando’s picture

FileSize
26.07 KB

Worked on this some more. Still needs #2161337: Add a Date Range field type with support for end date as a base, https://www.drupal.org/files/issues/2161337-216.patch to be exact. That issue has seen progress in the meantime, which is not yet reflected here.

Please note that this is proof of concept code, very unfinished. You're welcome though to help work out a good architecture here. I am still thinking whether the data model is solid. Maybe a pseudo-field (read-only) for the individual occurences would be good as well. I still am hesitant to use regular field storage for individual occurences because there can be lots of them and this was in D7 a major performance problem, and usually they are not needed all (but field api makes it AFAICS obligatory to always load all deltas).

dankegel’s picture

https://www.drupal.org/node/2699477 has settled down :-), date ranges are now experimental in D8.2.

A newbie recipe for trying this against 8.2 might be handy.

Frando’s picture

Status: Needs work » Needs review

I continued working on a repeating date solution for Drupal 8. For now, I released a first alpha of date_recur - see: https://www.drupal.org/project/date_recur.

I am still interested in including the code within datetime_extras. Won't post a patch for now, please review date_recur-8.x-1.0-alpha1.

Frando’s picture

Issue summary: View changes
Frando’s picture

I again worked some more on date_recur. Please review the 8.x-1.x branch (not the first alpha, which is obsolete).

I'd say this is may be ready for beta soon. Reviews by datetime maintainers would be highly appreciated!

Frando’s picture

Issue summary: View changes
Frando’s picture

Frando’s picture

I just released 1.0-alpha3 version of date_recur, filling some major feature gaps. Still interested in reviews from datetime maintainers and/or updates on plans whether this should move into datetime_extras.

mpdonadio’s picture

Sorry, I haven't had time yet to give this a proper test drive. I like the approach, especially not creating rows-upon-rows of entries for the dates. TBH, I almost of the option of putting this in now.

iantresman’s picture

I had made a feature suggestion for the D7 version of Date Repeat here, and add my summary here, in case there is something that may be found useful to consider.

Features to consider:

  1. Event From date, to To date
  2. Repeating date (Frequency and Period)
  3. Repeating Until date
  4. Advanced repeating options (Months, Days, Nth day of week)
  5. Exception (a) dates (b) date ranges
  6. Additional (a) dates (b) date ranges
  7. Input formatting options (a) As dates (b) As text, eg. "Every second Saturday" per PHP strtotime
  8. Output formatting options: Good use of classes to differentiate output
  9. Support for Microdata/RDF/Schema.org
  10. Support for Views, including (a) Is/Is not, a repeating date (b) is a date that repeats daily/weekly/monthly/annually (optional negation)
mpdonadio’s picture

#15, are all of those supported by RRULE in RFC 2445? That is really important for interchange.

Frando’s picture

To answer #15 for the current state of D8 date_recur:

1. Event From date, to To date

This is supported.

2. Repeating date (Frequency and Period)

This is supported.

3. Repeating Until date

This is supported.

4. Advanced repeating options (Months, Days, Nth day of week)

Quite some options are provided, more could be added to the widget if needed (this would only need changes in the JS code as long as RRULE and php-rrule support it).

5. Exception (a) dates (b) date ranges

This is not yet supported.

6. Additional (a) dates (b) date ranges

This is somehow supported by making the date_recur field a multivalue field. Could be improved though to unite the display.

7. Input formatting options (a) As dates (b) As text, eg. "Every second Saturday" per PHP strtotime

Text input is not yet supported. rrule.js has some NLP parsing, so could be added.

8. Output formatting options: Good use of classes to differentiate output

Output is easily themeable.

9. Support for Microdata/RDF/Schema.org

Dates are printed in the same way as Drupal core date fields, which has some semantic markup.

Support for Views, including (a) Is/Is not, a repeating date (b) is a date that repeats daily/weekly/monthly/annually (optional negation)

Only normal Views support is there by now (listing dates e.g. in a list of upcoming dates or in a calendar).
I need a) too so this will be added soon. b) is more difficult and not yet supported by the current architecture. It might be possible in a simple, but likely limited way by using a text filter on the rrule field (e.g. contains "BYDAY").

bkosborne’s picture

@Frado,

How does your solution handle the situation with views, where you want to display each occurrence separately? See http://drupal.stackexchange.com/questions/17015/how-to-use-recurring-dat... for more info

You'd want to be able to render each date recurrence independently in the result of the view.

Frando’s picture

There's an open issue for this: https://www.drupal.org/node/2846298
This is solveable via a custom views field renderer. I'll work on this soonish.

MrPaulDriver’s picture

Version: » 8.x-1.x-dev

Not strictly related, but I'd like to cross reference with Date Repeat Entity as progress there, will likely be dependent on progress here.

Frando’s picture

I recently released a new alpha (alpha4) that includes support for excluding/including dates and makes the occurrence handling pluggable, which allows to add more features via add-on modules also. It should be possible to base a Drupal 8 port of date repeat entity on date_recur. If someone is interested in doing this feel free to ping me for some guidance.

mpdonadio’s picture

@Frando, do you want to keep your module standalone, or add it here? If you want to keep it standalone (which may let you work more quickly on it), I think we should close this issue and point people to your project. And thanks for keeping that moving; recurrences are a complicated mess.

heddn’s picture

Status: Needs review » Needs work

The repeating date stuff should be moved into a sub "modules" folder of the project.

dpi’s picture

Status: Needs work » Fixed

Date recur has since made significant progress in stability, testing, and ecosystem. I think its safe to close this issue.

dpi’s picture

Perhaps a message could be added to the project page re DR. Judging by the amount of followers in this issue there seems to be interest.

colan’s picture

Component: Code » Documentation
Status: Fixed » Needs work

Agreed.

dww’s picture

Status: Needs work » Fixed

Added a "Other D8 date-related projects of interest" section to the project page with a link to date_recur.

Thanks,
-Derek

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.