From: PHO Date: Thu, 11 Mar 2010 05:19:10 +0000 (+0900) Subject: data W3CDateTime X-Git-Tag: RELEASE-0.1.0.1~15 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-w3c.git;a=commitdiff_plain;h=0094b747a40329d173a21eb8faa72d89abe35444 data W3CDateTime --- diff --git a/Data/Time/W3CDateTime.hs b/Data/Time/W3CDateTime.hs index 3f10f99..a0de70e 100644 --- a/Data/Time/W3CDateTime.hs +++ b/Data/Time/W3CDateTime.hs @@ -1,4 +1,55 @@ module Data.Time.W3CDateTime - ( + ( W3CDateTime ) where + +import Data.Convertible +import Data.Fixed +import Data.Time +import Data.Typeable + + +-- 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). +data W3CDateTime + = W3CDateTime { + w3cYear :: !Integer + , w3cMonth :: !(Maybe Int) + , w3cDay :: !(Maybe Int) + , w3cHour :: !(Maybe Int) + , w3cMinute :: !(Maybe Int) + , w3cSecond :: !(Maybe Pico) + , w3cTimeZone :: !(Maybe TimeZone) + } + deriving (Show, Eq, Typeable) + +empty :: W3CDateTime +empty = W3CDateTime { + w3cYear = 0 + , w3cMonth = Nothing + , w3cDay = Nothing + , w3cHour = Nothing + , w3cMinute = Nothing + , w3cSecond = Nothing + , w3cTimeZone = Nothing + } + +instance Convertible Day W3CDateTime where + safeConvert day + = case toGregorian day of + (y, m, d) -> return empty { + w3cYear = y + , w3cMonth = Just m + , w3cDay = Just d + } + +instance Convertible W3CDateTime Day where + safeConvert w3c + = do let y = w3cYear w3c + m <- case w3cMonth w3c of + Just m -> return m + Nothing -> convError "No month info" w3c + d <- case w3cDay w3c of + Just d -> return d + Nothing -> convError "No day info" w3c + return $ fromGregorian y m d \ No newline at end of file diff --git a/w3cdatetime.cabal b/w3cdatetime.cabal index e21596e..1308ccd 100644 --- a/w3cdatetime.cabal +++ b/w3cdatetime.cabal @@ -6,7 +6,7 @@ Synopsis: Parse and format W3C Date and Time -- Description: License: PublicDomain -License-file: LICENSE +License-file: COPYING Author: PHO Maintainer: PHO Stability: Experimental @@ -21,7 +21,13 @@ Library Data.Time.W3CDateTime Build-depends: - base >= 4 && < 5 + base >= 4 && < 5, + convertible >= 1.0, + time >= 1.1 + + Extensions: + DeriveDataTypeable + MultiParamTypeClasses GHC-Options: -Wall