A DSMR timestamp.
DSMR timestamps contain a naive date and time. Some telegrams also include a
daylight saving time marker: "W" for winter time or "S" for summer time.
Summary
Types
@type t() :: %DSMR.Timestamp{dst: binary() | nil, value: NaiveDateTime.t()}
Functions
@spec to_datetime(t()) :: {:ok, DateTime.t()} | {:error, :missing_dst}
Converts a timestamp to a UTC DateTime.
DSMR timestamps are Dutch local time; the DST marker disambiguates the UTC
offset ("W" means UTC+1, "S" means UTC+2). The fixed offsets make this
conversion work without a timezone database dependency.
Returns {:error, :missing_dst} for timestamps without a DST marker
(found in DSMR 2.2/3.0 telegrams), as their UTC offset is ambiguous around
the DST transitions.
Examples
iex> DSMR.Timestamp.to_datetime(%DSMR.Timestamp{value: ~N[2017-01-02 19:20:02], dst: "W"})
{:ok, ~U[2017-01-02 18:20:02Z]}
iex> DSMR.Timestamp.to_datetime(%DSMR.Timestamp{value: ~N[2017-07-02 19:20:02], dst: "S"})
{:ok, ~U[2017-07-02 17:20:02Z]}
iex> DSMR.Timestamp.to_datetime(%DSMR.Timestamp{value: ~N[2017-01-02 19:20:02]})
{:error, :missing_dst}