roseblade / silverstripe-opening-hours
Regular opening hours and special hours (holidays, Christmas closures) for SilverStripe, with announcements that show and hide themselves, and optional schema.org structured data.
Package info
github.com/RosebladeMedia/silverstripe-opening-hours
Type:silverstripe-vendormodule
pkg:composer/roseblade/silverstripe-opening-hours
Requires
- php: ^8.3
- silverstripe/asset-admin: ^3.0
- silverstripe/framework: ^6.0
- spatie/opening-hours: ^4.2
Requires (Dev)
- phpunit/phpunit: ^11.3
Suggests
- roseblade/businessdata: Adds the opening hours to the site's JSON-LD structured data
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-12-01 08:04:19 UTC
README
Regular opening hours and special hours (bank holidays, Christmas closures, stocktakes) for SilverStripe CMS 6. Special hours can be announced on the site ahead of time and disappear on their own once they've passed.
Features
- Regular weekly hours, including split days (for example, closed for lunch)
- Special hours periods, such as "Christmas opening hours", made up of single dates or date ranges that are either closed or open at different times
- Each period has a title, an optional message and image, and a "show from" date. It shows on the site from that date until its last date, then hides itself
- Template helpers for the week grouped into readable lines ("Monday – Friday: 8:30am – 5:00pm"), today's hours and "open now"
- schema.org
openingHoursSpecificationandspecialOpeningHoursSpecificationadded to roseblade/businessdata's JSON-LD when it's installed - Works on SiteConfig out of the box, and on any other DataObject (for example, branches) with one line of config
- Schedule logic is handled by spatie/opening-hours
Requirements
- SilverStripe CMS 6
- PHP 8.3+
Installation
composer require roseblade/silverstripe-opening-hours vendor/bin/sake db:build --flush
The CMS fields appear under Settings > Opening Hours.
Usage
There's a step-by-step user guide for CMS editors, with worked examples for Christmas and bank holidays.
Entering hours
Regular opening hours: add one row per day and time range. A day with no rows shows as closed. Add two rows for the same day if you close for part of it. If no rows are added at all, no regular hours are shown.
Special opening hours: add a period (for example "Christmas opening hours"), save it, then add its dates. Each date row is either a single date or a range, and is either "Closed all day" or open at its own times. If a date has both a closed row and an open row, closed wins.
A period shows on the site from its "Show on the website from" date (or its first date, if that's blank) until its last date. Its dates apply to the opening hours whenever they fall, whether or not the period is showing yet.
Templates
The quickest way is the included template, used within the owner's scope:
<% with $SiteConfig %>
<% include Roseblade\OpeningHours\Includes\OpeningHours %>
<% end_with %>
Or build your own markup with these helpers, all available on the owner ($SiteConfig by default):
| Helper | Returns |
|---|---|
$HasWeeklyHours |
Whether any regular hours are set |
$WeeklyHoursSummary |
The week grouped by identical hours. Each item has $Days ("Monday – Friday"), $Hours ("8:30am – 5:00pm" or "Closed"), $IsClosed and $IsToday |
$CurrentSpecialHours |
Special hours periods showing today, soonest first. Each has $Title, $Message, $Image and $DateSummary |
$DateSummary (on a period) |
The period's dates from today onwards, grouped. Each item has $Dates ("Thursday 24 December – Sunday 3 January"), $Hours, $IsClosed and $Note |
$TodaysHours |
Today's hours as text, special hours included |
$IsOpenNow |
Whether open right now. Avoid on pages that are cached |
For example:
<% with $SiteConfig %>
<% loop $CurrentSpecialHours %>
<h3>{$Title}</h3>
<% if $Message %><p>{$Message}</p><% end_if %>
<ul>
<% loop $DateSummary %><li>{$Dates}: {$Hours}</li><% end_loop %>
</ul>
<% end_loop %>
<% if $HasWeeklyHours %>
<dl>
<% loop $WeeklyHoursSummary %><dt>{$Days}</dt><dd>{$Hours}</dd><% end_loop %>
</dl>
<% end_if %>
<% end_with %>
In PHP, getOpeningHours() returns a Spatie\OpeningHours\OpeningHours object for anything else, such as the next opening time.
Structured data
If roseblade/businessdata is installed and the business type is set to Local Business, the regular hours are added as openingHoursSpecification, and upcoming special dates as specialOpeningHoursSpecification. Closed dates are marked with opens and closes times of 00:00, as schema.org recommends. Nothing else needs setting up.
Configuration
Roseblade\OpeningHours\Extension\HasOpeningHours: # Timezone for "today" and "open now". Defaults to PHP's default timezone. timezone: 'Europe/London' # PHP date() formats time_format: 'g:ia' # 9:00am date_format: 'l j F' # Thursday 24 December # CMS tab for the fields cms_tab: 'Root.OpeningHours'
Adding opening hours to another DataObject
App\Model\Branch: extensions: - Roseblade\OpeningHours\Extension\HasOpeningHours
The same fields and template helpers then work on that record, for example <% loop $Branches %>{$TodaysHours}<% end_loop %>.
Limitations
- Times that run past midnight (for example 18:00 to 02:00) aren't supported. Enter them as two rows on consecutive days.
- Regular hours are sorted in the CMS using MySQL's enum ordering. On other databases the display on the website is still correct, but the CMS list may not be in day order.
Contributing
See CONTRIBUTING.md. Pull requests go against develop.
Licence
BSD-3-Clause. See LICENSE.