# Timeloop Repeating date field by CraftPulse. Creates recurring dates (daily, weekly, monthly, yearly) without complex inputs — editors pick a frequency, cycle, and optional end date. Exposes a Twig variable API, a `recurringDates()` function for cross-entry queries, and full GraphQL support. CraftPulse's own plugin. `craftpulse/craft-timeloop` — Free (internal) ## Documentation - GitHub: https://github.com/craftpulse/craft-timeloop - Packagist: https://packagist.org/packages/craftpulse/craft-timeloop Source lives at `~/dev/craft-plugins/v5/craft-timeloop/src/`. When in doubt, read the source directly. ## Common Pitfalls - Not setting an end date — without `loopEndDate`, the plugin defaults to start + 20 years. That's 7,300+ daily entries. Always set a sane end date or use `limit` in `getDates()`. - Expecting `getUpcoming()` to return an array — it returns a single `DateTime|null` (the next occurrence). For multiple upcoming dates, use `getDates()` with a limit. - Monthly frequency without timestring — when using monthly recurrence, set the ordinal + day (e.g., "second Tuesday") via the field UI. Without it, the plugin uses raw month arithmetic with end-of-month correction, which may not be what editors expect. - Using `recurringDates()` on large element queries — the Twig function iterates every element and computes loops per entry. Pre-filter with element criteria to avoid performance hits. - Forgetting `.eagerly()` on relation fields that carry Timeloop fields — the Timeloop field normalizes to a `TimeloopModel`, not a relation, so N+1 isn't the issue. But if the Timeloop field lives on a related entry type, eager-load the relation itself. - `loopPeriod` stored as JSON text — the field stores its value as a JSON string in a TEXT column. Custom queries against the raw DB value need `JSON_EXTRACT` or similar. ## Field Configuration The Timeloop field has one setting: | Setting | Type | Description | |---------|------|-------------| | `showTime` | boolean | Enable time selection on start/end dates | ## Data Model The field normalizes to a `TimeloopModel` with these properties: | Property | Type | Description | |----------|------|-------------| | `loopStartDate` | `DateTime\|null` | Recurrence start | | `loopEndDate` | `DateTime\|null` | Recurrence end (null = +20 years) | | `loopStartTime` | `DateTime\|null` | Start time (when `showTime` enabled) | | `loopEndTime` | `DateTime\|null` | End time (when `showTime` enabled) | | `loopPeriod` | `array\|null` | `{ frequency, cycle, days[], timestring }` | | `loopReminderValue` | `int\|null` | Reminder offset value | | `loopReminderPeriod` | `string\|null` | Reminder offset unit (`days`, `weeks`, etc.) | ### Period Frequencies | Frequency code | Meaning | Cycle example | |---------------|---------|---------------| | `P1D` | Daily | Every `cycle` days | | `P1W` | Weekly | Every `cycle` weeks (with optional `days[]` selection) | | `P1M` | Monthly | Every `cycle` months (with optional ordinal + day timestring) | | `P1Y` | Yearly | Every `cycle` years | ## Twig API ### Variable: `craft.timeloop` Access via the `craft.timeloop` variable on any element's Timeloop field value: ```twig {% set timeloopData = entry.myTimeloopField %} {# Next upcoming occurrence — returns DateTime|null #} {% set next = craft.timeloop.getUpcoming(timeloopData) %} {% if next %} {% endif %} {# Next 5 upcoming dates — returns DateTime[] #} {% set dates = craft.timeloop.getDates(timeloopData, 5) %} {% for date in dates %}