git.iko.soy/typeable/timezone-olson
on master help sign in
Remove UnknownType constructor, default TransitionType is Wall.
commitb691560da57e82f174e99cc055de96d4ef7861c6 authorYitzchak Gale <gale@sefer.org> dateMon 17 May 2010, 17:55 (16 years ago) parent5d501f7
2 files changed+16−10
Data/Time/LocalTime/TimeZone/Olson/Parse.hs+15−9 Data/Time/LocalTime/TimeZone/Olson/Types.hs+1−1
Data/Time/LocalTime/TimeZone/Olson/Parse.hs+15−9
@@ -125,9 +125,8 @@ getOlsonPart verifyMagic getTime = do
125125 (version,
126126 OlsonData
127127 (zipWith Transition times indexes)
128− (map (flip lookupAbbr abbr_chars) . zipWith setTtype ttinfos .
129− (++ repeat UnknownType) $
130− zipWith boolsToTType (map Just isstds ++ repeat Nothing) isgmts)
128+ (map (flip lookupAbbr abbr_chars) . zipWith setTtype ttinfos $
129+ zipWithExtend boolsToTType False False isstds isgmts)
131130 leaps
132131 Nothing
133132 )
@@ -135,11 +134,18 @@ getOlsonPart verifyMagic getTime = do
135134 lookupAbbr (TtInfo gmtoff isdst ttype abbrind) =
136135 TtInfo gmtoff isdst ttype . takeWhile (/= '\NUL') . drop abbrind
137136 setTtype ttinfo ttype = ttinfo {tt_ttype = ttype}
138− boolsToTType _ isgmt | isgmt = UTC
139− boolsToTType isstd _ = maybe UnknownType stdOrWall isstd
140− stdOrWall isstd
141− | isstd = Std
142− | otherwise = Wall
137+ boolsToTType _ isgmt | isgmt = UTC
138+ boolsToTType isstd _
139+ | isstd = Std
140+ | otherwise = Wall
141+
142+-- A variant of zipWith whose result is the length of the longer
143+-- rather than the shorter list, by extending the shorter list with
144+-- a default value
145+zipWithExtend :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c]
146+zipWithExtend f x0 y0 (x:xs) (y:ys) = f x y : zipWithExtend f x0 y0 xs ys
147+zipWithExtend f x0 _ [] ys = map (f x0) ys
148+zipWithExtend f _ y0 xs _ = map (flip f y0) xs
143149
144150-- Parse a POSIX-style TZ string.
145151-- We don't try to understand the TZ string, we just pass it along whole.
@@ -160,7 +166,7 @@ getTtInfo = do
160166 gmtoff <- get32bitInt
161167 isdst <- getBool
162168 abbrind <- get8bitInt
163− return $ TtInfo gmtoff isdst UnknownType abbrind
169+ return $ TtInfo gmtoff isdst Wall abbrind
164170
165171-- Parse leap second info. (usually not used)
166172getLeapInfo :: Integral a => Get a -> Get LeapInfo
Data/Time/LocalTime/TimeZone/Olson/Types.hs+1−1
@@ -80,7 +80,7 @@ data Transition =
8080-- zone. This historical trivia may seem rather boring, but
8181-- unfortunately it is needed to interpret a POSIX-style TZ string
8282-- timezone specification correctly.
83−data TransitionType = Std | Wall | UTC | UnknownType
83+data TransitionType = Std | Wall | UTC
8484 deriving (Eq, Ord, Show)
8585
8686-- | A @TtInfo@ is a specification of local time in a timezone for