elm-community/elm-time/3.0.3

NOTE: this package is not compatible with Elm 0.19.1

Time.Iso8601

Render ISO8601 strings

fromDate : Date -> String

fromDate renders a Date in ISO8601 format.

import Time.Date exposing (..)


date 2018 5 27
|> fromDate
--> "2018-05-27"
fromDateTime : DateTime -> String

fromDateTime renders a DateTime in ISO8601 format.

import Time.DateTime exposing (..)


epoch
|> addMilliseconds 61000
|> fromDateTime
--> "1970-01-01T00:01:01.000Z"
fromZonedDateTime : ZonedDateTime -> String

fromZonedDateTime renders a ZonedDateTime in ISO8601 format.

import Time.ZonedDateTime
import Time.TimeZones exposing (america_new_york)
import Time.DateTime exposing (epoch)


Time.ZonedDateTime.fromDateTime (america_new_york ()) epoch
|> fromZonedDateTime
--> "1969-12-31T19:00:00.000-05:00"

Parse ISO8601 strings

toDate : String -> Result Error Date

toDate parses an ISO8601-formatted date string into a Date. import Time.Date

toDate "1970-12-01"
--> Ok (Time.Date.date 1970 12 1)


toDate "19701201"
--> Ok (Time.Date.date 1970 12 1)
toDateTime : String -> Result Error DateTime

toDateTime parses an ISO8601-formatted date time string into a DateTime object, adjusting for its timezone offset.

toZonedDateTime : TimeZone -> String -> Result Error ZonedDateTime

toZonedDateTime parses an ISO8601-formatted string into a ZonedDateTime object, adjusting for its offset.

import Time.ZonedDateTime
import Time.TimeZones exposing (america_new_york)
import Time.DateTime exposing (epoch)


toZonedDateTime (america_new_york ()) "1970-01-01T00:00:00.000Z"
--> Ok (Time.ZonedDateTime.fromDateTime (america_new_york ()) epoch)