apostrophe
Version:
Apostrophe is a user-friendly content management system. You'll need more than this core module. See apostrophenow.org to get started.
37 lines (30 loc) • 1.32 kB
HTML
{# Output a time. Pass the entire timestamp, not just the time. #}
{% macro formatTime(when) %}
{{ when | date('h:mm a') }}
{% endmacro %}
{# Outputs a date and, if present, a time. The date is presented without the year unless it #}
{# is a different year than the present year. Pass the entire timestamp, not just date, and #}
{# pass the time (if the time is null, it is not output). #}
{% macro formatDateAndTime(when, timePresent) %}
{%- if aposIsCurrentYear(when) -%}
{{ when | date('MMM DD') }}
{%- else -%}
{{ when | date('MMM DD [\']YY') }}
{%- endif -%}
{%- if (timePresent) -%}
{{ ' ' }}{{ when | date('h:mm a') }}
{%- endif -%}
{% endmacro %}
{# Given an item, copes with startDate, startTime, endDate and endTime, all but the first of which #}
{# are optional, and outputs something reasonable for each combination. Used by RSS feeds, search results, #}
{# and (by default) events. #}
{%- macro formatDateRange(item) -%}
{{ formatDateAndTime(item.start, item.startTime) }}
{%- if (item.startDate == item.endDate) and (item.startTime != item.endTime) -%}
{{ ' ' }}–{{ ' ' }}
{{ formatTime(item.end) }}
{%- elif (item.startDate != item.endDate) -%}
{{ ' ' }}–{{ ' ' }}
{{ formatDateAndTime(item.end, item.endTime) }}
{%- endif -%}
{%- endmacro -%}