isaacseymour / deprecated-time / Time.Iso8601

Render ISO8601 strings

fromDate : Time.Date.Date -> String

fromDate renders a Date in ISO8601 format.

import Time.Date exposing (..)

date 2018 5 27
|> fromDate
--> "2018-05-27"

fromDateTime : Time.DateTime.DateTime -> String

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 : Time.ZonedDateTime.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 (List IsoDeadEnd) Time.Date.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) Time.DateTime.DateTime

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

toZonedDateTime : TimeZone -> String -> Result (List IsoDeadEnd) Time.ZonedDateTime.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 Basics.Int Basics.Int Basics.Int
    | ExpectingDot
    | ExpectingZ
    | ExpectingSign
    | BadInt
    | InvalidDate (( Basics.Int, Basics.Int, Basics.Int ))
    | ExpectingNDigits Basics.Int String
    | Other String

Issues parsing an ISO8601 date