{%- capture api -%} events

{%- endcapture -%} {%- include api/save.html -%} {%- assign now = “now” | date: “%s” | plus: 0 -%} {%- assign format = include.format | default: “%B %-d %A” -%} {%- assign day_seconds = 86400 -%} {%- assign year_seconds = day_seconds | times: 364 -%} {%- comment -%} LOOP CALENDARS {%- endcomment -%} {%- for calendar in site.data.tempus.events -%} {% if include.calendar == nil or include.calendar == calendar.title %}

**{{ calendar.title }}**

{%- if include.from or calendar.from or include.past == false -%}
  {%- assign start = include.from | default: calendar.from | date: "%s" | plus: 0 -%}
{%- else -%}
  {%- assign start = "now" | date: "%s" | plus: 0 -%}
{%- endif -%}
{%- if include.to or calendar.to -%}
  {%- assign end = include.to | default: calendar.to | date: "%s" -%}
{%- else -%}
  {%- comment -%} ADD ONE YEAR FROM THE START {%- endcomment -%}
  {%- assign end = start | plus: year_seconds -%}
{%- endif -%}
{%- comment -%} CALCULATE DAYS {%- endcomment -%}
{%- assign days = end | minus: start | divided_by: day_seconds | round -%}
{%- comment -%} LOOP DAYS {%- endcomment -%}
{%- for d in (0..days) -%}
  {%- assign increment = d | times: day_seconds -%}
  {%- assign day = start | plus: increment -%}
  {%- assign week_day = day | date: "%A" -%}
  {%- assign loop_day = day | date: "%Y-%m-%d" -%}
  {%- assign found = false -%}
  {%- for e in calendar.events -%}
    {% if include.event == nil or include.event == e.title %}
      {%- comment -%} DAY EVENT {%- endcomment -%}
      {%- if e.day -%}
        {%- assign event_date = e.day | date: "%Y-%m-%d" -%}
        {%- if loop_day == event_date -%}
          {%- assign found = true -%}
          {%- assign unix = e.day | date: "%s" | plus: 0 -%}
          {%- assign difference = unix | plus: day_seconds | minus: now | divided_by: day_seconds | ceil | times: -1 -%}
          {% if difference == 0 %}{%- assign difference = "today" -%}{% endif %}

{%- endif -%} {%- endfor -%}