# Hours of operation

## Hours formatter

Example of starting the formatter by passing primary hours of a location

```markup
{% set hours = location.hours_by_type.primary|hours_formatter %}
```

### Hours formatter options

Additional options can be passed to the formatter to change its behavior. Example of passing in options

```
|hours_formatter(disable_special_hours=True)
```

#### Available options

* `disable_special_hours` (default False) - This option disables using special hours when listing the days' hours. By default, when outputting hours they will be contextual to any special hours coming up for a day. For example, if is Monday and there is special hours for this Thursday, it will adjust the hours listed to show the special hours on Thursday.&#x20;

## 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 />`

```markup
<p>{{ hours.as_br() }}</p>
<p>{{ hours.as_br(hide_closed_days=True) }}</p>
<p>{{ hours.as_br(group_days=True) }}</p>
```

### `filtered_days`

For custom templating options. Below example of outputting the hours into a table.

```markup
<table>
{% for day in hours.filtered_days(hide_closed_days=True) %}
  <tr>
    <td>{{ day.label }}</td>
    <td>{{ day.content }}</td>
  </tr>
{% endfor %}
</table>
```

#### Multiple time ranges in a day

Days can also have multiple ranges of time that they are open. For example if the location is closed for lunch but then opens again for dinner.

By default, the value of `day.content` will have both ranges separated by commas.

`9:00 AM - 12:00 PM, 5:00 PM - 9:00 PM`

If you want more formatting options, you can also loop over each range within your template using `day.ranges.items`. If there is no ranges, then the day is closed and `day.content` is used to display "Closed"

```html
<td>{{ day.label }}</td>
<td>
    {% if day.ranges.items %}
        {% for range in day.ranges.items %}
            <span>{{ range.content }}</span>
        {% endfor %}
    {% else %}
        <span>{{ day.content }}</span>
    {% endif %}
</td>
```

## Other utilities

### `special_hours_days`

This can be used to list upcoming special hours dates and times for a location.

```html
<table>
{% for day in hours.special_hours_days() %}
  <tr>
    <td>{{ day.label }}</td>
    <td>{{ day.content }}</td>
  </tr>
{% endfor %}
</table>
```

Example output

```
<table>
  <tr>
    <td>Dec 25</td>
    <td>Closed</td>
  </tr>
  <tr>
    <td>Jan 1</td>
    <td>8:00 am - 12:00 pm</td>
  </tr>
</table>
```

#### Additional options

Additional options can be passed into the `special_hours_days`

* `day_format` - Specify the format to be used for each day's label. Default is `'%b %-d'`. Example of another would be `%b %-d, %Y` which would output the days as `Jan 1, 2022`
* `days_in_future` - Number of days into the future to get special hours. Default is `30` to show upcoming special hours in the next 30 days.

**Example**

```
{{ hours.special_hours_days(day_format='%b %-d, %Y', days_in_future=90) }}
```

### `todays_hours`

Output the content of todays hours

```markup
{{ hours.todays_hours }}
```

### Finder Support for todays\_hours

```
<p>{{location.todays_hours_of_operation}}</p>
```

### `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

```markup
{% if hours.all_days_closed() %}
<p>This location is closed this week</p>
{% endif %}
```

### `is_open_now`

Check to see if this location is currently open. This uses the location timezone.

```markup
{% if hours.is_open_now(location=location) %}
  <p>Open Now</p>
{% endif %}
```

### `closes_next`

Get the next "closing time". Only use this if you know that the location is currently open (using `is_open_now`).

```markup
<p>Closes at: {{ hours.closes_next(location=location) }}</p>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.devhub.com/themes-and-custom-templates/hours-of-operation.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
