BACnet.Protocol.DateRange (bacstack v0.1.0-dev.1)

Copy Markdown View Source

A Date Range defines an inclusive period bounded by a start BACnet.Protocol.BACnetDate and an end BACnet.Protocol.BACnetDate. It is one of the three CHOICE alternatives inside BACnet.Protocol.CalendarEntry (alongside a specific BACnet.Protocol.BACnetDate and a BACnet.Protocol.WeekNDay pattern).

Date ranges are the natural way to express holiday blocks, maintenance windows, or temporary schedule overrides that span multiple consecutive days.

BACnet Specification References

  • ASN.1 (Clause 21): BACnetDateRange ::= SEQUENCE { startDate Date, endDate Date }
  • Usage (Clause 12):
    • date_list property of Calendar objects (as BACnet.Protocol.CalendarEntry CHOICE)
    • exception_schedule of Schedule objects (as BACnet.Protocol.SpecialEvent.period)
    • ReadRange "by time" requests (start/stop as date+time)
  • Both endpoints are inclusive.

This module also provides a small helper to convert a fully-specified range into an Elixir Date.Range for easier processing.

Examples

iex> range = %DateRange{
...>   start_date: %BACnetDate{year: 2025, month: 6, day: 1, weekday: 7},
...>   end_date: %BACnetDate{year: 2025, month: 6, day: 30, weekday: 1}
...> }
iex> {:ok, elixir_range} = DateRange.get_date_range(range)
iex> elixir_range.first
~D[2025-06-01]

See Also

Summary

Types

t()

Inclusive start/end date pair used inside BACnet.Protocol.CalendarEntry and BACnet.Protocol.SpecialEvent (and for ReadRange by time). Dates may contain wildcards.

Functions

Encodes a BACnet date range into BACnet application tags encoding.

Get a Date.Range struct for this date range. Only specific dates are allowed.

Parses a BACnet date range from BACnet application tags encoding.

Validates whether the given BACnet date range is in form valid.

Types

t()

@type t() :: %BACnet.Protocol.DateRange{
  end_date: BACnet.Protocol.BACnetDate.t(),
  start_date: BACnet.Protocol.BACnetDate.t()
}

Inclusive start/end date pair used inside BACnet.Protocol.CalendarEntry and BACnet.Protocol.SpecialEvent (and for ReadRange by time). Dates may contain wildcards.

Functions

encode(date_range, opts \\ [])

@spec encode(t(), Keyword.t()) ::
  {:ok, BACnet.Protocol.ApplicationTags.encoding_list()} | {:error, term()}

Encodes a BACnet date range into BACnet application tags encoding.

get_date_range(date_range)

@spec get_date_range(t()) :: {:ok, Date.Range.t()} | {:error, term()}

Get a Date.Range struct for this date range. Only specific dates are allowed.

parse(tags)

Parses a BACnet date range from BACnet application tags encoding.

valid?(t)

@spec valid?(t()) :: boolean()

Validates whether the given BACnet date range is in form valid.

It only validates the struct is valid as per type specification.