dmy / elm-imf-date-time / Imf.DateTime

Convert Internet Message Format date and time strings to and from POSIX times.

Supported Internet Message Format specifications are RFC5322, as well as the obsolete RFC2822 and RFC822.

toPosix : String -> Result (List Parser.DeadEnd) Time.Posix

Convert from an Internet Message Format date and time string to a POSIX time.

Regardless of which time zone the string uses, this function normalizes it and returns a time in UTC.

In accordance to RFC2822 then RFC5322:

If parsing fails, a List Parser.DeadEnd is returned. Install elm/parser and see Parser.DeadEnd for producing helpful error messages.

Examples:

import Time

Imf.DateTime.toPosix "1 Jan 70 00:00:00 GMT"
--> Ok (Time.millisToPosix 0)


Imf.DateTime.toPosix "Wed, 31 Dec 69 19:00:00 EST"
--> Ok (Time.millisToPosix 0)

fromPosix : Time.Zone -> Time.Posix -> String

Convert a Time.Zone and a Time.Posix to an Internet Message Format date and time string.

Examples:

import Time

epoch : Time.Posix
epoch =
    Time.millisToPosix 0

Imf.DateTime.fromPosix Time.utc epoch
--> "Thu, 01 Jan 1970 00:00:00 +0000"

Imf.DateTime.fromPosix (Time.customZone 60 []) epoch
--> "Thu, 01 Jan 1970 01:00:00 +0100"

Imf.DateTime.fromPosix
    (Time.customZone -300 [])
    (Time.millisToPosix 1357891860000)
--> "Fri, 11 Jan 2013 03:11:00 -0500"

parser : Parser Time.Posix

Internet Message Format date and time Parser for elm/parser.