X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-w3c.git;a=blobdiff_plain;f=Data%2FTime%2FW3CDateTime.hs;fp=Data%2FTime%2FW3CDateTime.hs;h=a0de70ee8d554b19a22eff6f2d83e4772d4bedbf;hp=3f10f99991f388f0b445a99e075698eae3a217de;hb=0094b747a40329d173a21eb8faa72d89abe35444;hpb=903e5836ee49fe6ab3c982d70523de07d3bbc1a0 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