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
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
+ }