Package

purescript-datetime-iso

Repository
jmackie/purescript-datetime-iso
License
MIT
Uploaded by
jmackie
Published on
2019-08-07T16:01:49Z

Pursuit version Build status

2018-01-31T20:15:40.343Z

Description

Provides a minimal DateTime wrapper that encodes/decodes to/from the simplified extended ISO format (ISO 8601); specifically YYYY-MM-DDTHH:mm:ss[.sss]Z where hyphens and colons can be omitted.

If you're handling dates that aren't in this format you should check out the purescript-formatters package instead.

Installation

bower install purescript-datetime-iso

Usage

Here's a motivating example:

module Data.Event where

import Prelude

import Data.DateTime.ISO (ISO, unwrapISO)
import Data.Argonaut.Decode (class DecodeJson, decodeJson, (.?))
import Data.DateTime (DateTime)
import Data.Newtype (unwrap)

newtype Event = Event
    { timestamp   :: DateTime
    , description :: String
    }

instance decodeJsonEvent :: DecodeJson Event where
    decodeJson json = do
        obj <- decodeJson json
        timestamp <- obj .? "timestamp" <#> unwrapISO
        description <- obj .? "description"
        pure $ Event { timestamp, description }

Documentation

Module documentation is published on Pursuit.