BACnet. Protocol. CalendarEntry
(bacstack v0.1.0-dev.2)
View Source
A Calendar Entry is the CHOICE type used by both Calendar objects and Schedule objects to describe "special" days (holidays, maintenance periods, after-hours operation, etc.).
The three alternatives (defined in Clause 21) are:
:date- a single specific (or partially unspecified)BACnet.Protocol.BACnetDate:date_range- an inclusiveBACnet.Protocol.DateRange:week_n_day- a recurringBACnet.Protocol.WeekNDaypattern
This single type is deliberately reused in multiple places so that matching logic ("does today match any exception?") can be written once.
BACnet Specification References
- ASN.1 (Clause 21):
BACnetCalendarEntry ::= CHOICE { date Date, dateRange BACnetDateRange, weekNDay BACnetWeekNDay } - Calendar object (12.9):
date_listproperty is aBACnetLISTof entries. - Schedule object (12.24):
exception_schedulecontainsBACnet.Protocol.SpecialEventwhoseperiodcan be aBACnet.Protocol.CalendarEntryor an object identifier referencing a Calendar object.
Examples
Specific date entry
iex> entry = %CalendarEntry{type: :date, date: %BACnetDate{year: 2025, month: 12, day: 25, weekday: 4}, date_range: nil, week_n_day: nil}
iex> entry.type
:dateDate range entry
iex> entry = %CalendarEntry{type: :date_range, date_range: %DateRange{start_date: %BACnetDate{year: 2025, month: 7, day: 1, weekday: 2}, end_date: %BACnetDate{year: 2025, month: 7, day: 31, weekday: 4}}, date: nil, week_n_day: nil}
iex> entry.type
:date_rangeRecurring WeekNDay entry
iex> entry = %CalendarEntry{type: :week_n_day, week_n_day: %WeekNDay{month: :unspecified, week_of_month: 3, weekday: 2}, date: nil, date_range: nil}
iex> entry.type
:week_n_daySee Also
Summary
Types
CHOICE of a single date, date range, or BACnet.Protocol.WeekNDay pattern
(see BACnet.Protocol.CalendarEntry module docs + ASN.1 in Clause 21).
Used in Calendar date_list and Schedule exception schedules.
Functions
Encode a calendar entry into application tag-encoded.
Matches an entry against an explicitly supplied ISO calendar date.
Parse application tag-encoded calendar entry into a struct.
Validates whether the given BACnet calendar entry is in form valid.
Validates an entry's date-matching semantics.
Types
@type t() :: %BACnet.Protocol.CalendarEntry{ date: BACnet.Protocol.BACnetDate.t() | nil, date_range: BACnet.Protocol.DateRange.t() | nil, type: :date | :date_range | :week_n_day, week_n_day: BACnet.Protocol.WeekNDay.t() | nil }
CHOICE of a single date, date range, or BACnet.Protocol.WeekNDay pattern
(see BACnet.Protocol.CalendarEntry module docs + ASN.1 in Clause 21).
Used in Calendar date_list and Schedule exception schedules.
Functions
@spec encode(t(), Keyword.t()) :: {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}
Encode a calendar entry into application tag-encoded.
Matches an entry against an explicitly supplied ISO calendar date.
All specified date/pattern fields must match - Sunday is weekday 7. Impossible date patterns never match and are not clamped to month-end. Ranges are inclusive and support fully unspecified/open endpoints. WeekNDay's numbered weeks start at day 1 - weeks 6..9 are seven-day blocks counted backwards from month-end.
Returns false for entries that fail valid_for_matching?/1. Uses only the
supplied entry and date.
@spec parse(BACnet.Protocol.ApplicationTags.encoding_list()) :: {:ok, {t(), rest :: BACnet.Protocol.ApplicationTags.encoding_list()}} | {:error, term()}
Parse application tag-encoded calendar entry into a struct.
Validates whether the given BACnet calendar entry is in form valid.
It only validates the struct is valid as per type specification.
Validates an entry's date-matching semantics.
Unlike structural valid?/1, this enforces the CHOICE's unused fields being
nil and the range endpoint rules: each endpoint is fully unspecified or an
actual fully specified date, with start no later than end. Special date values
and partial wildcards belong in the date alternative, not range endpoints.
Endpoint weekdays do not affect range ordering - inconsistent endpoint weekdays
are accepted using their year/month/day (the local-matter policy of 20.2.12).