packages feed

timezone-olson 0.1.9 → 0.2.0

raw patch · 7 files changed

+50/−60 lines, 7 files

Files

Data/Time/LocalTime/TimeZone/Olson.hs view
@@ -1,19 +1,16 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Time.LocalTime.TimeZone.Olson--- Copyright   :  Yitzchak Gale 2018+-- Copyright   :  Yitzchak Gale 2019 -- -- Maintainer  :  Yitzchak Gale <gale@sefer.org> -- Portability :  portable -- -- A parser and renderer for binary Olson timezone files whose format--- are specified by the tzfile(5) man page on Unix-like systems. For--- more information about this format, see--- <http://www.twinsun.com/tz/tz-link.htm>. Functions are provided for--- converting the parsed data into @TimeZoneSeries@ and @TimeZone@--- objects.+-- is specified by RFC 8536. Functions are provided for converting the+-- parsed data into @TimeZoneSeries@ and @TimeZone@ objects. -{- Copyright (c) 2018 Yitzchak Gale. All rights reserved.+{- Copyright (c) 2019 Yitzchak Gale. All rights reserved. For licensing information, see the BSD3-style license in the file LICENSE that was originally distributed by the author together with this file. -}
Data/Time/LocalTime/TimeZone/Olson/Parse.hs view
@@ -3,18 +3,16 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Time.LocalTime.TimeZone.Olson.Parse--- Copyright   :  Yitzchak Gale 2018+-- Copyright   :  Yitzchak Gale 2019 -- -- Maintainer  :  Yitzchak Gale <gale@sefer.org> -- Portability :  portable -- -- A parser for binary Olson timezone files whose format is specified--- by the tzfile(5) man page on Unix-like systems. For more--- information about this format, see--- <http://www.twinsun.com/tz/tz-link.htm>. Functions are provided for--- converting the parsed data into 'TimeZoneSeries' objects.+-- in RFC 8536. Functions are provided for converting the parsed data+-- into 'TimeZoneSeries' objects. -{- Copyright (c) 2018 Yitzchak Gale. All rights reserved.+{- Copyright (c) 2019 Yitzchak Gale. All rights reserved. For licensing information, see the BSD3-style license in the file LICENSE that was originally distributed by the author together with this file. -}@@ -65,8 +63,8 @@   where     dflt = fromMaybe dflt0 . listToMaybe $ filter isStd ttinfos     isStd (TtInfo _ isdst _ _) = not isdst-    mkTZ (TtInfo gmtoff isdst _ abbr) =-      TimeZone ((gmtoff + 30) `div` 60) isdst abbr+    mkTZ (TtInfo utoff isdst _ abbr) =+      TimeZone ((utoff + 30) `div` 60) isdst abbr     lookupTZ ttinfos ttime = fmap (((,) $ toUTC ttime) . mkTZ) . listToMaybe $                              drop (transIndex ttime) ttinfos     toUTC = posixSecondsToUTCTime . fromIntegral . transTime@@ -119,6 +117,13 @@             verify (const False) msg undefined  -- Parse the part of an Olson file that contains timezone data++-- We are lenient about invalid values of @isstdcnt@ and @isutcnt@.+-- Before RFC 8536, we ignored transitions that did not have a+-- corresponding value for both @isstd@ and @isut@.  Staring with RFC+-- 8536, when zero became a valid value for @isstdcont@ and @isutcnt@,+-- we extend @isstds@ and @isuts@ with default values if they are too+-- short. Thanks to Github user @mniip@ for suggesting this change. getOlsonPart :: Integral a => Bool -> SizeLimits -> Get a ->                 Get (Word8, OlsonData) getOlsonPart verifyMagic limits getTime = do@@ -126,7 +131,7 @@     when verifyMagic $ verify_ (== "TZif") "missing magic number" magic     version <- getWord8     replicateM_ 15 getWord8 -- padding nulls-    tzh_ttisgmtcnt <- get32bitInt+    tzh_ttisutcnt <- get32bitInt     tzh_ttisstdcnt <- get32bitInt     tzh_leapcnt <- get32bitInt       >>= verify (withinLimit maxLeaps) "too many leap second specifications"@@ -134,7 +139,7 @@       >>= verify (withinLimit maxTimes) "too many timezone transitions"     tzh_typecnt <- get32bitInt       >>= verify (withinLimit maxTypes) "too many timezone type specifications"-    verify (withinLimit maxTypes) "too many isgmt specifiers" tzh_ttisgmtcnt+    verify (withinLimit maxTypes) "too many isut specifiers" tzh_ttisutcnt     verify (withinLimit maxTypes) "too many isstd specifiers" tzh_ttisstdcnt     tzh_charcnt <- get32bitInt       >>= verify (withinLimit maxAbbrChars) "too many tilezone specifiers"@@ -144,33 +149,27 @@     abbr_chars <- fmap (toASCII . B.unpack) $ getByteString tzh_charcnt     leaps <- replicateM tzh_leapcnt $ getLeapInfo getTime     isstds <- replicateM tzh_ttisstdcnt getBool-    isgmts <- replicateM tzh_ttisgmtcnt getBool+    isuts <- replicateM tzh_ttisutcnt getBool     return       (version,        OlsonData          (zipWith Transition times indexes)          (map (flip lookupAbbr abbr_chars) . zipWith setTtype ttinfos $-           zipWithExtend boolsToTType False False isstds isgmts)+           zipWith boolsToTType+             (isstds ++ repeat False) (isuts ++ repeat False)+         )          leaps          Nothing       )   where     withinLimit limit value = maybe True (value <=) $ limit limits-    lookupAbbr (TtInfo gmtoff isdst ttype abbrind) =-      TtInfo gmtoff isdst ttype . takeWhile (/= '\NUL') . drop abbrind+    lookupAbbr (TtInfo utoff isdst ttype abbrind) =+      TtInfo utoff isdst ttype . takeWhile (/= '\NUL') . drop abbrind     setTtype ttinfo ttype = ttinfo {tt_ttype = ttype}-    boolsToTType _     isgmt | isgmt     = UTC+    boolsToTType _     isut | isut      = UTC     boolsToTType isstd _-                             | isstd     = Std-                             | otherwise = Wall---- A variant of zipWith whose result is the length of the longer--- rather than the shorter list, by extending the shorter list with--- a default value-zipWithExtend :: (a -> b -> c) -> a -> b -> [a] -> [b] -> [c]-zipWithExtend f x0 y0 (x:xs) (y:ys) = f x y : zipWithExtend f x0 y0 xs ys-zipWithExtend f x0 _  []     ys     = map (f x0) ys-zipWithExtend f _  y0 xs     _      = map (flip f y0) xs+                            | isstd     = Std+                            | otherwise = Wall  -- Parse a POSIX-style TZ string. -- We don't try to understand the TZ string, we just pass it along whole.@@ -188,10 +187,10 @@ -- Data.Time.TimeZone object. getTtInfo :: Get (TtInfo Int) getTtInfo = do-    gmtoff <- get32bitInt+    utoff <- get32bitInt     isdst <- getBool     abbrind <- get8bitInt-    return $ TtInfo gmtoff isdst Wall abbrind+    return $ TtInfo utoff isdst Wall abbrind  -- Parse leap second info. (usually not used) getLeapInfo :: Integral a => Get a -> Get LeapInfo
Data/Time/LocalTime/TimeZone/Olson/Render.hs view
@@ -2,17 +2,15 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Time.LocalTime.TimeZone.Olson.Render--- Copyright   :  Yitzchak Gale 2018+-- Copyright   :  Yitzchak Gale 2019 -- -- Maintainer  :  Yitzchak Gale <gale@sefer.org> -- Portability :  portable ----- Render Olson timezone data in the standard binary format as used in--- Olson timezone files, and as specified by the tzfile(5) man page on--- Unix-like systems. For more information about this format, see--- <http://www.twinsun.com/tz/tz-link.htm>.+-- Render Olson timezone data in the standard binary format used in+-- Olson timezone files, as specified in RFC 8536. -{- Copyright (c) 2018ZZ Yitzchak Gale. All rights reserved.+{- Copyright (c) 2019 Yitzchak Gale. All rights reserved. For licensing information, see the BSD3-style license in the file LICENSE that was originally distributed by the author together with this file. -}@@ -146,7 +144,7 @@     putWord8 version     putByteString . B.pack $ replicate 15 0 -- padding nulls     replicateM_ 2 $ putCount ttinfosWithTtype-                               -- tzh_ttisgmtcnt+                               -- tzh_ttisutcnt                                -- tzh_ttisstdcnt     putCount leaps             -- tzh_leapcnt     putCount transs            -- tzh_timecnt@@ -158,7 +156,7 @@     mapM_ putAbbr abbrStrings     mapM_ (putLeapInfo putTime) leaps     mapM_ (putBool . (== Std) . tt_ttype) ttinfosWithTtype -- isstd-    mapM_ (putBool . (== UTC) . tt_ttype) ttinfosWithTtype -- isgmt+    mapM_ (putBool . (== UTC) . tt_ttype) ttinfosWithTtype -- isut   where     putCount = put32bitIntegral . length     ttinfosWithTtype = takeWhile ((<= UTC) . tt_ttype) ttinfosIndexed@@ -167,8 +165,8 @@     putAbbr abbr = putASCII "time zone abbreviation" abbr >> putWord8 0     abbrAssocs = zip abbrStrings . scanl (+) 0 $                  map ((+ 1) . length) abbrStrings-    ttinfosIndexed = [TtInfo gmtoff isdst ttype i |-      TtInfo gmtoff isdst ttype abbr <- ttinfos,+    ttinfosIndexed = [TtInfo utoff isdst ttype i |+      TtInfo utoff isdst ttype abbr <- ttinfos,       i <- maybeToList $ lookup abbr abbrAssocs]  putPosixTZ :: Maybe String -> Put@@ -179,7 +177,7 @@  putTtInfo :: TtInfo Int -> Put putTtInfo tt = do-    put32bitIntegral $ tt_gmtoff tt+    put32bitIntegral $ tt_utoff tt     putBool $ tt_isdst tt     put8bitIntegral $ tt_abbr tt 
Data/Time/LocalTime/TimeZone/Olson/Types.hs view
@@ -3,19 +3,17 @@ ----------------------------------------------------------------------------- -- | -- Module      :  Data.Time.LocalTime.TimeZone.Olson.Types--- Copyright   :  Yitzchak Gale 2018+-- Copyright   :  Yitzchak Gale 2019 -- -- Maintainer  :  Yitzchak Gale <gale@sefer.org> -- Portability :  portable ----- Data types to represent timezone data as used in Olson timezone--- files, and as specified by the tzfile(5) man page on Unix-like--- systems. For more information about this format, see--- <http://www.twinsun.com/tz/tz-link.htm>.+-- Data types to represent timezone data used in Olson timezone files,+-- as specified by RFC 8536. ----- Both Version 1 and Version 2 timezone data can be represented.+-- Both Version 1, 2, and 3 timezone data can be represented. -{- Copyright (c) 2018 Yitzchak Gale. All rights reserved.+{- Copyright (c) 2019 Yitzchak Gale. All rights reserved. For licensing information, see the BSD3-style license in the file LICENSE that was originally distributed by the author together with this file. -}@@ -127,7 +125,7 @@ -- timezone file). data TtInfo abbr =         TtInfo-         {tt_gmtoff :: Int, -- ^ The offset of local clocks from UTC,+         {tt_utoff :: Int,  -- ^ The offset of local clocks from UTC,                             -- in seconds           tt_isdst :: Bool, -- ^ True if local clocks are summer time           tt_ttype :: TransitionType,
LICENSE view
@@ -1,4 +1,4 @@-Copyright (c) 2010-2018 Yitzchak Gale. All rights reserved.+Copyright (c) 2010-2019 Yitzchak Gale. All rights reserved.  Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are
README.md view
@@ -3,9 +3,7 @@ On Hackage: [timezone-olson](http://hackage.haskell.org/package/timezone-olson)  This package provides a parser and renderer for binary Olson timezone-files whose format is specified by the tzfile(5) man page on Unix-like-systems. For more information about this format, see-[the IANA timezone database site](https://www.iana.org/time-zones).+files whose format is specified in RFC 8536.  Functions are provided for converting the parsed data into `TimeZoneSeries` objects from the@@ -19,7 +17,7 @@ package for a way to include timezone informaton from a binary Olson timezone file at compile time. -Copyright (c) 2010-2018 Yitzchak Gale. All rights reserved.+Copyright (c) 2010-2019 Yitzchak Gale. All rights reserved.  For licensing information, see the BSD3-style license in the file LICENSE that was originally distributed by the author together with
timezone-olson.cabal view
@@ -1,5 +1,5 @@ Name:                timezone-olson-Version:             0.1.9+Version:             0.2.0 Synopsis:            A pure Haskell parser and renderer for binary Olson timezone files Description:         A parser and renderer for binary Olson timezone                      files whose format is specified by the tzfile(5)@@ -25,7 +25,7 @@ Build-type:          Simple Extra-source-files:  README.md, catTZ.hs, hzdump.hs Cabal-version:       >=1.10-Tested-with:         GHC > 8.0 && < 8.5+Tested-with:         GHC ==8.8.1 || ==8.6.5 || ==8.4.4 || ==8.2.2 || ==8.0.2  Source-repository HEAD   type:              git