BACnet.Protocol.BACnetDateTime (bacstack v0.0.1)

View Source

A BACnet DateTime is used to represent date with timepoints. It wraps both BACnetDate and BACnetTime.

This module provides some helpers to convert DateTime and NaiveDateTime into a BACnetDateTime and back.

Summary

Types

t()

Represents a BACnet DateTime. It wraps both BACnet Date and Time.

Functions

Compares two BACnet DateTime.

Encodes the given BACnet DateTime into an application tag.

Converts a DateTime to a BACnet DateTime.

Converts a NaiveDateTime to a BACnet DateTime.

Parses a BACnet DateTime from BACnet application tags encoding.

Checks whether the given BACnet DateTime is a specific date-time value (every component is a numeric value).

Converts the BACnet DateTime to a NaiveDateTime.

Creates a new BACnet DateTime for the current UTC datetime.

Validates whether the given BACnet datetime is in form valid.

Types

t()

@type t() :: %BACnet.Protocol.BACnetDateTime{
  date: BACnet.Protocol.BACnetDate.t(),
  time: BACnet.Protocol.BACnetTime.t()
}

Represents a BACnet DateTime. It wraps both BACnet Date and Time.

Functions

compare(dt1, dt2)

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

Compares two BACnet DateTime.

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

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

encode(dt, opts \\ [])

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

Encodes the given BACnet DateTime into an application tag.

For tagged encoding, you'll have to strip this down further using manual efforts.

from_datetime(dt)

@spec from_datetime(DateTime.t()) :: t()

Converts a DateTime to a BACnet DateTime.

from_naive_datetime(dt)

@spec from_naive_datetime(NaiveDateTime.t()) :: t()

Converts a NaiveDateTime to a BACnet DateTime.

parse(tags)

Parses a BACnet DateTime from BACnet application tags encoding.

specific?(dt)

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

Checks whether the given BACnet DateTime is a specific date-time value (every component is a numeric value).

to_datetime(dt, timezone \\ Application.get_env(:bacstack, :default_timezone, "Etc/UTC"), time_zone_database \\ Calendar.get_time_zone_database())

@spec to_datetime(t(), Calendar.time_zone(), Calendar.time_zone_database()) ::
  {:ok, DateTime.t()} | {:error, term()}

Converts the BACnet DateTime to a DateTime.

to_datetime!(dt, timezone \\ Application.get_env(:bacstack, :default_timezone, "Etc/UTC"), time_zone_database \\ Calendar.get_time_zone_database())

Bang-version of to_datetime/1.

to_naive_datetime(dt)

@spec to_naive_datetime(t()) :: {:ok, NaiveDateTime.t()} | {:error, term()}

Converts the BACnet DateTime to a NaiveDateTime.

to_naive_datetime!(dt)

@spec to_naive_datetime!(t()) :: NaiveDateTime.t() | no_return()

Bang-version of to_naive_datetime/1.

utc_now()

@spec utc_now() :: t()

Creates a new BACnet DateTime for the current UTC datetime.

valid?(t)

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

Validates whether the given BACnet datetime is in form valid.

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