Skip to main content

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, 2023, this would return the Date object of 2023-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 - 2023-04-15 23:59:59 in this case
  • previousDate
    • Returns a Date object of the previous day relative to the date property, e.g. 2023-04-14 00:00:00 in this case
  • nextDate
    • Returns a Date object of the next day relative to the date property, e.g. 2023-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 2023-04-09 and ending in 2023-04-21 assuming the Day object's date is 2023-04-15
  • containsDate(dateObject)
    • Returns true if the dateObject provided is within the Day object's date range. Typically used for handling CSS and title behavior in Month view templates for events that span multiple days.
    • E.g. day.containsDate(event.startDateLocalized) would return true if the Day object would be April 15, 2023, and the event.startDateLocalized would be 2023-04-15 17:30:00, but false if the event.startDateLocalized would be 2023-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 %}

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 %}