BACnet. Protocol. WeekNDay
(bacstack v0.1.0-dev.2)
View Source
A WeekNDay (Week And Day) is a compact 3-component pattern used inside
BACnet.Protocol.CalendarEntry and BACnet.Protocol.SpecialEvent to describe
recurring days without listing every date.
Classic examples: "the third Tuesday of every month", "every Friday",
or "the last Sunday in odd months".
It is one of BACnet's most powerful yet bandwidth-efficient calendar primitives.
BACnet Specification References
- ASN.1 (Clause 21):
BACnetWeekNDay ::= SEQUENCE { month (1..12 | 13 | 14 | 255), -- 13=odd, 14=even, 255=unspecified weekOfMonth (1..9 | 255), -- 6 = last 7 days, 255=unspecified dayOfWeek (1..7 | 255) } - Primary usage (Clause 12.9 Calendar, 12.24 Schedule):
- Inside
BACnet.Protocol.CalendarEntry(as one of the three CHOICE alternatives) - Inside
BACnet.Protocol.SpecialEventfor exception schedules - Combined with
BACnet.Protocol.DaysOfWeekin destinations and notification rules
- Inside
The week-of-month numbering (1 = days 1-7, 6 = last 7 days of month) is defined in the production comments and is independent of the actual calendar month length. Values 7, 8 and 9 select the seven-day blocks immediately before the final 7, 14 and 21 days, respectively.
Examples
"Third Tuesday of every month"
iex> pattern = %WeekNDay{month: :unspecified, week_of_month: 3, weekday: 2}
iex> pattern.week_of_month
3"Last Sunday in December"
iex> last_sunday_dec = %WeekNDay{month: 12, week_of_month: 6, weekday: 7}
iex> last_sunday_dec.week_of_month
6Edge cases
Week 6 always means the last 7 days of the month, regardless of length:
iex> feb_last = %WeekNDay{month: 2, week_of_month: 6, weekday: 1} # last Monday in Feb
iex> feb_last.week_of_month
6When used inside a CalendarEntry or SpecialEvent, it can match the last few days even in short months (Feb 23-28 can be "week 6").
See Also
Summary
Types
Compact recurring-day pattern. Month supports odd/even/unspecified values - week and weekday support unspecified values.
Functions
Encodes a BACnet week and day into application tags encoding.
Parses a BACnet week and day from application tags encoding.
Validates whether the given BACnet week and day is in form valid.
Types
Functions
@spec encode(t(), Keyword.t()) :: {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}
Encodes a BACnet week and day into application tags encoding.
@spec parse(BACnet.Protocol.ApplicationTags.encoding_list()) :: {:ok, {t(), rest :: BACnet.Protocol.ApplicationTags.encoding_list()}} | {:error, term()}
Parses a BACnet week and day from application tags encoding.
Validates whether the given BACnet week and day is in form valid.
It only validates the struct is valid as per type specification.