This document is for an older version of

Calendar

.

View latest version →

Day object

A Day object holds in itself a list of all Events that fall into this day, as well as gives the possibility to iterate over Hour object's that fall into the range of this Day object.

Properties

  • date #
    • A Date object of the starting date of the event duration
    • For a Day object of April 15, 2016, this would return the Date object of 2016-04-15 00:00:00
  • startDate #
    • Basically the same as the date property
  • endDate #
    • The ending date of the Day object's day, e.g - 2016-04-15 23:59:59 in this case
  • previousDate #
    • Returns a Date object of the previous day relative to the date property, e.g. 2016-04-14 00:00:00 in this case
  • nextDate #
    • Returns a Date object of the next day relative to the date property, e.g. 2016-05-16 00:00:00 in this case
  • events #
    • Contains a list of Events that fall into this Day object's range
  • eventCount #
    • The number of events in the events property

Methods

  • dateRange(int before, int after) #
    • Returns a list of Date objects ranging before number of days before date and after number of days after date
    • E.g. day.dateRange(6, 6) would return a list starting from 2016-04-09 and ending in 2016-04-21 assuming the Day object's date is 2016-04-15
  • containsDate(dateObject) #
    • Returns true if the dateObject provided is within the Day object's date range
    • E.g. day.containsDate(event.startDate) would return true if the Day object would be April 15, 2016, and the event.startDate would be 2016-04-15 17:30:00, but false if the event.startDate would be 2016-04-16 00:00:00

Usage in Templates

Iterate through the hours of the day

{% set day = craft.calendar.day({
  date: "today",
  calendar: ["holidays", "sports"]
}) %}

{% for hour in day %}
  {% for event in hour.events %}
    <div style="{{ event.calendar.color }};">
      {{ event.title }}
    </div>
  {% endfor %}
{% endfor %}
1
2
3
4
5
6
7
8
9
10
11
12

Iterate through all events in the day

{% set day = craft.calendar.day({
  date: "today",
  calendar: ["holidays", "sports"]
}) %}

{% for event in day.events %}
  <div style="{{ event.calendar.color }};">
    {{ event.title }}
  </div>
{% endfor %}
1
2
3
4
5
6
7
8
9
10