Skip to content

Instantly share code, notes, and snippets.

@vfalconi
Created December 22, 2020 22:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vfalconi/bfc88bab23a23d8038bd70cb394a058a to your computer and use it in GitHub Desktop.
Save vfalconi/bfc88bab23a23d8038bd70cb394a058a to your computer and use it in GitHub Desktop.
super simple macro to format a timespan
{% macro timespan(timeA, timeB) %}
{% if timeB == null %}
{{ timeA }}
{% else %}
{% set testA = timeA|date('a') %}
{% set testB = timeB|date('a') %}
{% if testA == testB %}
{{ timeA|date('g:i') }}–{{ timeB|date('g:i') }} {{ timeA|date('a')}}
{% else %}
{{ timeA|date('g:i a') }}–{{ timeB|date('g:i a') }}
{% endif %}
{% endif %}
{% endmacro %}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment