View Source SMPPEX.Pdu.ValidityPeriod (smppex v3.2.1)
Module for converting validity period to Unix timestamp.
Module works both with the absolute format of validity period and with the relative one. In case of relative validity period, this module implements a naive representation of the month and year date shifting for the sake of simplicity.
Link to this section Summary
Functions
Converts validity_period/0
to Unix timestamp according to the SMPP specification.
Converts validity_period/0
to Unix timestamp according to the SMPP specification.
The same as to_timestamp/2
but raises an exception in case of error.
Link to this section Types
@type timestamp() :: non_neg_integer()
@type timestamp_origin() :: non_neg_integer()
@type validity_period() :: String.t()
Link to this section Functions
to_timestamp(validity_period, timestamp_origin \\ System.system_time(:second))
View Source@spec to_timestamp(validity_period(), timestamp_origin()) :: {:ok, timestamp()} | {:error, :invalid_validity_period}
Converts validity_period/0
to Unix timestamp according to the SMPP specification.
In case of the relative format, this function uses a naive implementation of the month and date shifting. To be clear, it takes one month as 30 days and one year as 12 months.
One who uses the function should implement the way how this time shift might be limited according to the SMPP specification:
- A MC operator may choose to impose a limit on relative time offsets, thus either rejecting a message that exceeds such a limit or reducing the offset to the maximum relative time allowed.
Returns {:ok, timestamp}
if conversion was successful.
Returns {:error, :invalid_validity_period}
if validity_period
is not consistent with the SMPP specification.
In case of internal errors, however, this function raises an exception.
example-relative-format
Example (relative format)
iex> timestamp_origin = ~N[2017-01-01 00:00:00] |>
...> DateTime.from_naive!("Etc/UTC") |>
...> DateTime.to_unix()
iex> timestamp = SMPPEX.Pdu.ValidityPeriod.to_timestamp!("000000000005000R", timestamp_origin)
iex> DateTime.from_unix!(timestamp) |> to_string()
"2017-01-01 00:00:05Z"
example-absolute-format
Example (absolute format)
iex> {:ok, timestamp} = SMPPEX.Pdu.ValidityPeriod.to_timestamp("170610233429004+")
iex> DateTime.from_unix!(timestamp) |> to_string()
"2017-06-10 22:34:29Z"
to_timestamp!(validity_period, timestamp_origin \\ System.system_time(:second))
View Source@spec to_timestamp!(validity_period(), timestamp_origin()) :: timestamp()
Converts validity_period/0
to Unix timestamp according to the SMPP specification.
The same as to_timestamp/2
but raises an exception in case of error.