View Source RFC2822.DateTime (rfc2822 v0.1.0)

The implementation of RFC 2822 <3.3. Date and Time Specification>.

When talking about date time string, RFC 1123 and RFC 2822 are using the same format.

Unsupported features

  • parsing string with zone except GMT / UT / UTC is not supported, such as Mon, 05 Mar 2018 00:00:00 +0000.

About UTC

In RFC 2822, UTC shouldn't be used as a timezone.

When producing a RFC 2822 date time string, we complied with this rule.

But, when parsing a RFC 2822 date time string, in order to support non-standard date time strings, we broke this rule.

Summary

Functions

Parses a string in the extended date time format described by RFC 2822.

Converts the given datetime to a string described by RFC 2822.

Functions

@spec parse(String.t()) :: {:ok, DateTime.t()} | {:error, atom()}

Parses a string in the extended date time format described by RFC 2822.

Example

iex> RFC2822.DateTime.parse("Mon, 01 Jan 2000 00:00:00 GMT")
{:ok, ~U[2000-01-01 00:00:00Z]}

iex> RFC2822.DateTime.parse("Mon, 01 Jan 2000 00:00:00 UT")
{:ok, ~U[2000-01-01 00:00:00Z]}

iex> RFC2822.DateTime.parse("Mon, 01 Jan 2000 00:00:00 UTC")
{:ok, ~U[2000-01-01 00:00:00Z]}
@spec to_string(Calendar.datetime()) :: String.t()

Converts the given datetime to a string described by RFC 2822.

Example

iex> RFC2822.DateTime.to_string(~U[2000-01-01 00:00:00Z])
"Sat, 01 Jan 2000 00:00:00 GMT"