BACnet.Protocol.BACnetDate (bacstack v0.0.1)

View Source

A BACnet Date is used to represent dates, but also can represent unspecific dates, such as a single component being unspecified (i.e. can match anything in that component), or can be something like targeting even or odd numbers.

This can be used, for example, for Calendar functionality (such as defining holidays occurring on the same day of year).

This module provides some helpers to convert Date into a BACnetDate and back.

Summary

Types

t()

Represents a BACnet Date, which can have unspecified (= any) or even/odd values.

Functions

Compares two BACnet Date.

Encodes the given BACnet Date into an application tag.

Converts a Date to a BACnet Date.

Parses a BACnet Date from BACnet application tags encoding.

Checks whether the given BACnet Date is a specific date value (every component is a numeric value, :last in the day component counts as specific).

Converts the BACnet Date to a Date.

Creates a new BACnet Date with the current UTC date.

Validates whether the given BACnet date is in form valid.

Types

t()

@type t() :: %BACnet.Protocol.BACnetDate{
  day: 1..31 | :even | :odd | :last | :unspecified,
  month: 1..12 | :even | :odd | :unspecified,
  weekday: 1..7 | :unspecified,
  year: 1900..2154 | :unspecified
}

Represents a BACnet Date, which can have unspecified (= any) or even/odd values.

Weekday specifies the day of the week, starting with monday to sunday (1-7).

Functions

compare(date1, date2)

@spec compare(t(), t()) :: :gt | :eq | :lt

Compares two BACnet Date.

Returns :gt if first date is later than the second, and :lt for vice versa. If the two dates are equal, :eq is returned.

Note that this is achieved by converting to Date and then comparing them.

encode(date, opts \\ [])

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

Encodes the given BACnet Date into an application tag.

from_date(date)

@spec from_date(Date.t()) :: t()

Converts a Date to a BACnet Date.

parse(tags)

Parses a BACnet Date from BACnet application tags encoding.

specific?(time)

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

Checks whether the given BACnet Date is a specific date value (every component is a numeric value, :last in the day component counts as specific).

to_date(date, ref_date \\ Date.utc_today())

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

Converts the BACnet Date to a Date.

If any of the fields are unspecified, the reference date (current UTC value) is used. In case of even or odd, either the current or the previous value of the reference date is used.

to_date!(date, ref_date \\ Date.utc_today())

@spec to_date!(t(), Date.t()) :: Date.t() | no_return()

Bang-version of to_date/1.

utc_today()

@spec utc_today() :: t()

Creates a new BACnet Date with the current UTC date.

valid?(t)

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

Validates whether the given BACnet date is in form valid.

It only validates the struct is valid as per type specification, it does not validate that the day matches the weekday.