From: PHO Date: Thu, 11 Mar 2010 06:42:40 +0000 (+0900) Subject: Convertible W3CDateTime ZonedTime X-Git-Tag: RELEASE-0.1.0.1~12 X-Git-Url: http://git.cielonegro.org/gitweb.cgi?p=time-w3c.git;a=commitdiff_plain;h=b848b3a392e2666d06533ad937c92c4d28085114 Convertible W3CDateTime ZonedTime --- diff --git a/Data/Time/W3CDateTime/Types.hs b/Data/Time/W3CDateTime/Types.hs index b41023c..c7573eb 100644 --- a/Data/Time/W3CDateTime/Types.hs +++ b/Data/Time/W3CDateTime/Types.hs @@ -53,22 +53,24 @@ instance Convertible W3CDateTime Day where d <- fetch "day" w3cDay w3c return (fromGregorian y m d) -instance Convertible UTCTime W3CDateTime where - safeConvert u - = let (y, m, d) = toGregorian (utctDay u) - hms = timeToTimeOfDay (utctDayTime u) +instance Convertible ZonedTime W3CDateTime where + safeConvert zt + = let lt = zonedTimeToLocalTime zt + tz = zonedTimeZone zt + ymd = localDay lt + hms = localTimeOfDay lt in return W3CDateTime { - w3cYear = y - , w3cMonth = Just m - , w3cDay = Just d + w3cYear = case toGregorian ymd of (y, _, _) -> y + , w3cMonth = Just (case toGregorian ymd of (_, m, _) -> m) + , w3cDay = Just (case toGregorian ymd of (_, _, d) -> d) , w3cHour = Just (todHour hms) , w3cMinute = Just (todMin hms) , w3cSecond = Just (todSec hms) - , w3cTimeZone = Just utc + , w3cTimeZone = Just tz } -instance Convertible W3CDateTime UTCTime where +instance Convertible W3CDateTime ZonedTime where safeConvert w3c = do day <- safeConvert w3c tod <- do h <- fetch "hour" w3cHour w3c @@ -78,5 +80,7 @@ instance Convertible W3CDateTime UTCTime where Just tod -> return tod Nothing -> convError "Invalid time of day" w3c tz <- fetch "timezone" w3cTimeZone w3c - let lt = LocalTime day tod - return (localTimeToUTC tz lt) + return ZonedTime { + zonedTimeToLocalTime = LocalTime day tod + , zonedTimeZone = tz + }