dmy/elm-imf-date-time/1.0.2

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 DeadEnd) 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:

  • Military time zones as defined in RFC822 and unknown uppercase alphabetic ones are considered equivalent to -0000 UTC offset.
  • Two digit years between 50 and 99 or three digits years are interpreted by adding 1900. Two digit years between 00 and 49 are interpreted by adding 2000.

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 : Zone -> Posix -> String

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

  • The day of week abbreviation will always be prefixed.
  • A four digit year is always used.
  • A signed four digit numerical UTC offset is always used.

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 Posix

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