]> gitweb @ CieloNegro.org - time-w3c.git/commitdiff
data W3CDateTime
authorPHO <pho@cielonegro.org>
Thu, 11 Mar 2010 05:19:10 +0000 (14:19 +0900)
committerPHO <pho@cielonegro.org>
Thu, 11 Mar 2010 05:19:10 +0000 (14:19 +0900)
Data/Time/W3CDateTime.hs
w3cdatetime.cabal

index 3f10f99991f388f0b445a99e075698eae3a217de..a0de70ee8d554b19a22eff6f2d83e4772d4bedbf 100644 (file)
@@ -1,4 +1,55 @@
 module Data.Time.W3CDateTime
 module Data.Time.W3CDateTime
-    (
+    ( W3CDateTime
     )
     where
     )
     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
index e21596e8ebedcbb3fb3c25804238462e9ccedbea..1308ccd59c46b82b219203a11c364430143bbfdb 100644 (file)
@@ -6,7 +6,7 @@ Synopsis:            Parse and format W3C Date and Time
 -- Description:
 
 License:             PublicDomain
 -- Description:
 
 License:             PublicDomain
-License-file:        LICENSE
+License-file:        COPYING
 Author:              PHO <pho AT cielonegro DOT org>
 Maintainer:          PHO <pho AT cielonegro DOT org>
 Stability:           Experimental
 Author:              PHO <pho AT cielonegro DOT org>
 Maintainer:          PHO <pho AT cielonegro DOT org>
 Stability:           Experimental
@@ -21,7 +21,13 @@ Library
         Data.Time.W3CDateTime
 
     Build-depends:
         Data.Time.W3CDateTime
 
     Build-depends:
-        base >= 4 && < 5
+        base >= 4 && < 5,
+        convertible >= 1.0,
+        time >= 1.1
+
+    Extensions:
+        DeriveDataTypeable
+        MultiParamTypeClasses
 
     GHC-Options:
         -Wall
 
     GHC-Options:
         -Wall