{%- capture api -%} Next 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 span_days = include.days | default: 2 -%} {%- assign span_seconds = day_seconds | times: span_days | plus: 1 -%} {%- comment -%} LOOP CALENDARS {%- endcomment -%} {%- for calendar in site.data.tempus.events -%} {%- if include.calendar == nil or include.calendar == calendar.title -%}

{%- assign start = now | minus: span_seconds -%}
{%- if include.past == false or include.past == "false" -%}{%- assign start = now | plus: 1 -%}{%- endif -%}
{%- assign end = now | plus: span_seconds -%}
{%- comment -%} CALCULATE DAYS {%- endcomment -%}
{%- assign days = end | minus: start | divided_by: day_seconds | round -%}
{%- comment -%} LOOP DAYS {%- endcomment -%}
{%- assign present = false -%}
{%- 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 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 -%}
            {%- if present == false -%}
              {% assign present = true %}

**{{ calendar.title }}**

  {%- endif -%}
{% assign found = true %}

**{{ calendar.title }}**

{%- endif -%}
{%- assign found = true -%}
{%- assign difference = day | minus: now | divided_by: day_seconds | ceil | times: -1 -%}
{% if difference == 0 %}{%- assign difference = "today" -%}{% endif %}

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