SMPPEX.Pdu.ValidityPeriod.to_timestamp

You're seeing just the function to_timestamp, go back to SMPPEX.Pdu.ValidityPeriod module for more information.
Link to this function

to_timestamp(validity_period, timestamp_origin \\ System.system_time(:second))

View Source

Specs

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)

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)

iex> {:ok, timestamp} = SMPPEX.Pdu.ValidityPeriod.to_timestamp("170610233429004+")
iex> DateTime.from_unix!(timestamp) |> to_string()
"2017-06-10 22:34:29Z"