isaacseymour/deprecated-time/1.0.0

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 renders a DateTime in ISO8601 format.

import Time.DateTime


Time.DateTime.epoch
|> Time.DateTime.addMilliseconds 61000
|> fromDateTime
--> "1970-01-01T00:01:01.000Z"

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 (List IsoDeadEnd) 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 (List IsoDeadEnd) DateTime

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

toZonedDateTime : TimeZone -> String -> Result (List IsoDeadEnd) 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)

Possible errors

type Problem
= ExpectingDigit
| ExpectingRange Int Int Int
| ExpectingDot
| ExpectingZ
| ExpectingSign
| BadInt
| InvalidDate ( Int, Int, Int )
| ExpectingNDigits Int String
| Other String

Issues parsing an ISO8601 date