I'm attempting to create something within my template using global values and checkboxes. What I need this to do is "if it's one of the days of the week marked as open, as selected by a checkbox, and the time is between X and Y, then display that we are open, otherwise, say we are closed".
I have Monday through Sunday listed as checkboxes, and their values are set with Monday as 1, Tuesday as 2, etc, and I'm trying to compare it to 'now'|date('N'), which lists the day of the week as a number.
{% for dayOfWeek in theCenter.openWeekDay %}
{% if 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTime|date('Hi') %}
<h3>We are OPEN</h3>
{% else %}
<h3>We are CLOSED</h3>
{% endif %}
{% endfor %}
I've selected Tuesday through Sunday as open by selecting their checkboxes in the globals form. The code above returns 5 'We are Closed' and 1 'We are Open' results. I just need it to check if today is one of the open days, and if it's between open and closing time, and display one result.
I've tried this:
{% if 'now'|date('N') in dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTime|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTime|date('Hi') %}
but it returns 6 'We are Closed'. I've been trying to figure this out for several hours, but the documentation doesn't seem to be made for what I want to do, and I'm probably looking in the wrong place.
Any suggestions on how I could get this to work?
EDIT
Here's the entire script:
{% if 'now'|date('z', 'America/Denver') > theCenter.startWinterSeason|date('z') or 'now'|date('z', 'America/Denver') < theCenter.endWinterSeason|date('z') %}
{% for dayOfWeek in theCenter.openDaysWinter %}
{% if dayOfWeek.selected and 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTimeWinter|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTimeWinter|date('Hi') %}
<h3>The center is OPEN</h3>
{% else %}
<h3>The center is CLOSED</h3>
{% endif %}
{% endfor %}
<div class="infoPane">
<p><i class="uk-icon-clock-o"></i> {{ theCenter.hoursTitleWinter }}</p>
<p>Tuesday — Saturday<br>{{ theCenter.openTimeWinter|date('g:i A') }} to {{ theCenter.closeTimeWinter|date('g:i A') }}</p>
<p class="uk-text-small">{{ theCenter.timeNotes|raw }}</p>
</div>
{% elseif 'now'|date('z', 'America/Denver') > theCenter.startSummerSeason|date('z') and 'now'|date('z', 'America/Denver') < theCenter.endSummerSeason|date('z') %}
{% for dayOfWeek in theCenter.openDaysSummer %}
{% if dayOfWeek.selected and 'now'|date('N') == dayOfWeek and 'now'|date('Hi', 'America/Denver') > theCenter.openTimeSummer|date('Hi') and 'now'|date('Hi', 'America/Denver') < theCenter.closeTimeSummer|date('Hi') %}
<h3>The center is OPEN</h3>
{% else %}
<h3>The center is CLOSED</h3>
{% endif %}
{% endfor %}
<div class="infoPane">
<p><i class="uk-icon-clock-o"></i> {{ theCenter.hoursTitleSummer }}</p>
<p>Tuesday — Saturday<br>{{ theCenter.openTimeSummer|date('g:i A') }} to {{ theCenter.closeTimeSummer|date('g:i A') }}</p>
<p class="uk-text-small">{{ theCenter.timeNotes|raw }}</p>
</div>
{% else %}
<h3>EPIC FAIL</h3>
{% endif %}
Which outputs this:
I need it to only show the center is closed once.
America/Denver
under Settings->General? Also, have you seen github.com/pixelandtonic/StoreHours? – Brad Bell Jan 3 '16 at 21:27openTime
andcloseTime
date/time fields set to just display the times? – Brad Bell Jan 3 '16 at 22:46