packages feed

tz 0.0.0.9 → 0.0.0.10

raw patch · 3 files changed

+39/−2 lines, 3 files

Files

Data/Time/Zones.hs view
@@ -28,6 +28,8 @@   loadTZFromDB,   loadSystemTZ,   loadLocalTZ,+  -- * Utilities+  diffForAbbr,   ) where  import Data.Bits (shiftR)@@ -155,7 +157,7 @@     res = if ix == VU.length trans           then FLUnique ix cand1 -- TODO(klao): extend when rule handling is added           else res'-               +     ix' = ix + 1     nextTrans = VU.unsafeIndex trans ix'     cand2 = lTime - fromIntegral (VU.unsafeIndex diffs ix')@@ -214,3 +216,25 @@     LTUNone ut _ -> ut     LTUUnique ut _ -> ut     LTUAmbiguous _ ut _ _ -> ut++--------------------------------------------------------------------------------+-- Random utility functions++-- | Returns /a/ time difference (in seconds) corresponding to the+-- abbreviation in the given time zone.+--+-- If there are multiple time differences associated with the same+-- abbreviation, the one corresponding to the latest use is+-- returned. (The latest use might be in the past or the future+-- depending on whether the abbreviation is still in use.)+--+-- This function is here for informational purpose only, do not use it+-- for time conversion. (Instead, use 'localTimeToUTCFull', and if the+-- result is ambiguous disambiguate between the possible results based+-- on the abbreviation.)+diffForAbbr :: TZ -> String -> Maybe Int+{-# INLINABLE diffForAbbr #-}+diffForAbbr (TZ _ diffs infos) s =+  case VB.findIndex ((==) s . snd) $ VB.reverse infos of+    Nothing -> Nothing+    Just i -> Just $ VU.unsafeIndex diffs (VU.length diffs - 1 - i)
tests/testTZ.hs view
@@ -161,6 +161,19 @@     LTUAmbiguous (mkUTC 2013 10 27  00 15 15) (mkUTC 2013 10 27  01 15 15)       zSummer zWinter +case_UTC_diffForAbbr = do+  tz <- loadTZFromDB "UTC"+  diffForAbbr tz "UTC" @?= Just 0+  diffForAbbr tz "XYZ" @?= Nothing++case_Paris_diffForAbbr = do+  tz <- loadTZFromDB "Europe/Paris"+  diffForAbbr tz "CET" @?= Just 3600+  diffForAbbr tz "CEST" @?= Just 7200+  diffForAbbr tz "WET" @?= Just 0+  diffForAbbr tz "LMT" @?= Just 561+  diffForAbbr tz "XYZ" @?= Nothing+ main :: IO () main = do   -- When we are running 'cabal test' the package is not yet
tz.cabal view
@@ -1,5 +1,5 @@ Name: tz-Version: 0.0.0.9+Version: 0.0.0.10 License: Apache-2.0 License-File: LICENSE Author: Mihaly Barasz, Gergely Risko