DevHub Docs
Search…
Hours of operation
Examples of formatting Location hours of operation

Hours formatter

Example of starting the formatter by passing primary hours of a location
1
{% set hours = location.hours_by_type.primary|hours_formatter %}
Copied!

Formatting options

Each of the following methods have a few options for outputting the hours
  • hide_closed_days (default False) - this option will exclude days that are closed
  • group_days (default False) - this option will group similar days that have the same hours to save the number of lines needed

as_br

Output hours one per line separated by <br />
1
<p>{{ hours.as_br() }}</p>
2
<p>{{ hours.as_br(hide_closed_days=True) }}</p>
3
<p>{{ hours.as_br(group_days=True) }}</p>
Copied!

filtered_days

For custom templating options. Below example of outputting the hours into a table.
1
<table>
2
{% for day in hours.filtered_days(hide_closed_days=True) %}
3
<tr>
4
<td>{{ day.label }}</td>
5
<td>{{ day.content }}</td>
6
</tr>
7
{% endfor %}
8
</table>
Copied!

Other utilities

todays_hours

Output the content of todays hours
1
{{ hours.todays_hours }}
Copied!

all_days_closed

Check to see if all days within the week are closed. It returns True/False. Can be used to hide a section if there are no open hours and instead show a different message
1
{% if hours.all_days_closed() %}
2
<p>This location is closed this week</p>
3
{% endif %}
Copied!

is_open_now

Check to see if this location is currently open. This uses the location timezone.
1
{% if hours.is_open_now(location=location) %}
2
<p>Open Now</p>
3
{% endif %}
Copied!

closes_next

Get the next "closing time". Only use this if you know that the location is currently open (using is_open_now).
1
<p>Closes at: {{ hours.closes_next(location=location) }}</p>
Copied!
Last modified 3mo ago