Hour object
An Hour object holds in itself a list of all Events that fall into this hour.
Properties
date- A Date object of the starting date of the event duration
- For an Hour object of April 15, 2023 at 5pm, this would return the Date object of
2023-04-15 17:00:00
startDate- Basically the same as the
dateproperty
- Basically the same as the
endDate- The ending date of the Hour object's hour, e.g -
2023-04-15 17:59:59in this case
- The ending date of the Hour object's hour, e.g -
previousDate- Returns a Date object of the previous hour relative to the
dateproperty, e.g.2023-04-15 16:00:00in this case
- Returns a Date object of the previous hour relative to the
nextDate- Returns a Date object of the next hour relative to the
dateproperty, e.g.2023-05-15 18:00:00in this case
- Returns a Date object of the next hour relative to the
events- Contains a list of Events that fall into this Hour object's range
eventCount- The number of events in the
eventsproperty
- The number of events in the
Methods
dateRange(int before, int after)- Returns a list of Date objects ranging
beforenumber of hours beforedateandafternumber of hours afterdate - E.g.
hour.dateRange(6, 6)would return a list starting from2023-04-15 11:00:00and ending in2023-04-15 23:00:00assuming the Day object'sdateis2023-04-15 17:00:00
- Returns a list of Date objects ranging
containsDate(dateObject)- Returns true if the
dateObjectprovided is within the Hour object's date range - E.g.
hour.containsDate(event.startDate)would return true if the Hour object would be April 15, 2023 at 5pm, and theevent.startDatewould be2023-04-15 17:30:00, but false if theevent.startDatewould be2023-04-16 18:00:00
- Returns true if the
Usage in Templates
Iterate through all events within the current hour
{% set hour = craft.calendar.day({
date: "now",
calendar: ["holidays", "sports"]
}) %}
{% for event in hour.events %}
<div style="{{ event.calendar.color }};">
{{ event.title }}
</div>
{% endfor %}