1 module Data.Time.W3C.Format
6 import Data.Convertible
9 import Data.Time.W3C.Types
12 format :: Convertible t W3CDateTime => t -> String
13 format = format' . convert
15 format' (W3CDateTime year Nothing Nothing Nothing Nothing Nothing Nothing)
18 format' (W3CDateTime year (Just month) Nothing Nothing Nothing Nothing Nothing)
19 = concat [show4 year, "-", show2 month]
21 format' (W3CDateTime year (Just month) (Just day) Nothing Nothing Nothing Nothing)
22 = concat [show4 year, "-", show2 month, "-", show2 day]
24 format' (W3CDateTime year (Just month) (Just day) (Just hour) (Just minute) Nothing (Just tz))
37 format' (W3CDateTime year (Just month) (Just day) (Just hour) (Just minute) (Just second) (Just tz))
48 , case properFraction second :: (Int, Pico) of
49 (int, 0 ) -> show2 int
50 (int, frac) -> show2 int ++ tail (show frac)
54 format' w = error ("Invalid W3C Date and Time: " ++ show w)
56 show4 :: Integral i => i -> String
58 | i >= 0 && i < 10 = "000" ++ show i
59 | i >= 0 && i < 100 = "00" ++ show i
60 | i >= 0 && i < 1000 = "0" ++ show i
61 | i >= 0 && i < 10000 = show i
62 | otherwise = error ("show4: the integer i must satisfy 0 <= i < 10000: " ++ show i)
64 show2 :: Integral i => i -> String
66 | i >= 0 && i < 10 = "0" ++ show i
67 | i >= 0 && i < 100 = show i
68 | otherwise = error ("show2: the integer i must satisfy 0 <= i < 100: " ++ show i)
70 showTZ :: TimeZone -> String
72 = case timeZoneMinutes tz of
73 offset | offset < 0 -> '-' : showTZ' (negate offset)
75 | otherwise -> '+' : showTZ' offset
78 = let h = offset `div` 60
81 concat [show2 h, ":", show2 m]