+-- | This package provides functionalities to parse and format W3C
+-- Date and Time. The package can also be used to convert it from/to
+-- 'Data.Time.Calendar.Day' and 'Data.Time.LocalTime.ZonedTime'.
+--
+-- See: <http://www.w3.org/TR/NOTE-datetime>
+
module Data.Time.W3C
( W3CDateTime(..)
, format
+-- | Format W3C Date and Time strings.
module Data.Time.W3C.Format
( format
)
import Data.Time.W3C.Types
+-- | Format W3C Date and Time string from anything convertible to
+-- 'W3CDateTime' type. The most obvious acceptable type is the
+-- 'W3CDateTime' itself.
format :: Convertible t W3CDateTime => t -> String
format = format' . convert
where
+-- | Parse W3C Date and Time string.
module Data.Time.W3C.Parser
( parse
)
import Data.Time.W3C.Parser.Parsec
import Data.Time.W3C.Types
+-- | Parse W3C Date and Time string to anything convertible from
+-- 'W3CDateTime' type. The most obvious acceptable type is the
+-- 'W3CDateTime' itself. If the given string is ill-formatted, 'parse'
+-- returns 'Prelude.Nothing'.
parse :: Convertible W3CDateTime t => String -> Maybe t
parse src = case P.parse p "" src of
Right w3c -> Just (convert w3c)
+-- | W3C Date and Time parser combinator for "Text.Parsec".
module Data.Time.W3C.Parser.Parsec
( w3cDateTime
)
import Data.Time.W3C.Types
import Text.Parsec
-
+-- | This is a parser combinator for "Text.Parsec".
w3cDateTime :: Stream s m Char => ParsecT s u m W3CDateTime
w3cDateTime = read4 >>= mdhmst
where
+-- | Data types defined by this package.
module Data.Time.W3C.Types
( W3CDateTime(..)
)
import Data.Typeable
+-- |'W3CDateTime' represents a W3C Date and Time format.
+--
+-- The field 'w3cYear' is mandatory while other fields are
+-- optional. But you should be careful about combinations of such
+-- optional fields. No combinations are allowed except for the
+-- following list:
+--
+-- * YYYY
+--
+-- * YYYY-MM
+--
+-- * YYYY-MM-DD
+--
+-- * YYYY-MM-DDThh:mmTZD
+--
+-- * YYYY-MM-DDThh:mm:ss.sTZD
+--
-- This data type is /partially ordered/ so we can't make it an
--- instance of Ord (e.g. "2010" and "2010-01" can't be compared).
+-- instance of Ord (e.g. @\"2010\"@ and @\"2010-01\"@ can't be
+-- compared).
data W3CDateTime
= W3CDateTime {
w3cYear :: !Integer
Version: 0.1
Synopsis: Parse, format and convert W3C Date and Time
Description:
- This module provides functionalities to parse and format W3C
- Date and Time. The module can also be used to convert it
+ This package provides functionalities to parse and format W3C
+ Date and Time. The package can also be used to convert it
from/to 'Data.Time.Calendar.Day' and
'Data.Time.LocalTime.ZonedTime'.
+ See: <http://www.w3.org/TR/NOTE-datetime>
+
License: PublicDomain
License-file: COPYING
Author: PHO <pho AT cielonegro DOT org>