time-exts 1.1.2 → 1.1.3
raw patch · 3 files changed
+23/−5 lines, 3 files
Files
- src/Data/Time/Exts/Local.hs +13/−4
- src/Data/Time/Exts/Unix.hs +9/−0
- time-exts.cabal +1/−1
src/Data/Time/Exts/Local.hs view
@@ -46,6 +46,7 @@ -- ** Time Zone Transition Times , Transition(..) , getTransitions+ , lastTransition -- ** Get Current Local Timestamps Using Preloaded Time Zone Transitions Times , getCurrentLocalDate'@@ -886,10 +887,10 @@ let file = getOlsonFile city Olson.OlsonData{..} <- Olson.getOlsonFromFile file let ttimes = uniquetimes $ sortBy future2past olsonTransitions- return $! foldr (step olsonTypes) [] ttimes+ return $! foldr (step olsonTypes) [] $ map last ttimes where uniquetimes = groupBy $ on (==) Olson.transTime future2past = comparing $ negate . Olson.transTime- step types ~[Olson.Transition{..}] accum =+ step types Olson.Transition{..} accum = if transTime < 0 then [Transition (LocalDateTime 43200 zone)] else Transition (LocalDateTime base zone) : accum@@ -898,6 +899,14 @@ base = baseUnixToUTC $ fromIntegral transTime zone = fromZone $ unabbreviate abbr +-- | Get the last time zone transition time for the given city and time.+lastTransition :: (DateTime dt, Unix dt) => City -> dt -> IO (Maybe Transition)+lastTransition city time = do+ ttimes <- getTransitions city+ return $! listToMaybe $ dropWhile f ttimes+ where base = baseUnixToUTC $ unixNorm time+ f tt = localBase tt > base+ -- | Get the current local date from the system clock. -- -- > >>> getCurrentLocalDate London @@ -1049,7 +1058,7 @@ -- > >>> getCurrentLocalDateTimePicos Karachi -- > 2013-11-04 22:05:17.556043000000 PKT ----- Note that this functions calls @gettimeofday()@ behind the scenes. Therefore, the resultant+-- Note that this functions calls @gettimeofday@ behind the scenes. Therefore, the resultant -- timestamp will have picosecond granularity, but only microsecond resolution. getCurrentLocalDateTimePicos :: City -> IO LocalDateTimePicos getCurrentLocalDateTimePicos city = getTransitions city >>= getCurrentLocalDateTimePicos'@@ -1065,7 +1074,7 @@ -- granularity more than once. The use of preloaded transition times will avoid unnecessary -- parsing of Olson files. ----- Note that this functions calls @gettimeofday()@ behind the scenes. Therefore, the resultant+-- Note that this functions calls @gettimeofday@ behind the scenes. Therefore, the resultant -- timestamp will have picosecond granularity, but only microsecond resolution. getCurrentLocalDateTimePicos' :: [Transition] -> IO LocalDateTimePicos getCurrentLocalDateTimePicos' ttimes = do
src/Data/Time/Exts/Unix.hs view
@@ -71,6 +71,9 @@ -- | Get the base component of a Unix timestamp. unixBase :: u -> Int64 + -- | Get the normalized base component of a Unix timestamp.+ unixNorm :: u -> Int64+ -- | Days since Unix epoch. newtype UnixDate = UnixDate { _uni_day_base :: Int32@@ -173,21 +176,27 @@ instance Unix UnixDate where unixBase = fromIntegral . get uni_day_base+ unixNorm = unixBase instance Unix UnixDateTime where unixBase = get uni_sec_base+ unixNorm = unixBase instance Unix UnixDateTimeMillis where unixBase = get uni_mil_base+ unixNorm = flip div 1000 . unixBase instance Unix UnixDateTimeMicros where unixBase = get uni_mic_base+ unixNorm = flip div 1000000 . unixBase instance Unix UnixDateTimeNanos where unixBase = get uni_nan_base+ unixNorm = flip div 1000000 . unixBase instance Unix UnixDateTimePicos where unixBase = get uni_pic_base+ unixNorm = flip div 1000000 . unixBase instance DateTimeMath UnixDate Day where date `plus` Day day =
time-exts.cabal view
@@ -1,5 +1,5 @@ Name: time-exts-Version: 1.1.2+Version: 1.1.3 License: BSD3 License-File: LICENSE Copyright: Copyright (c) 2014, Enzo Haussecker. All rights reserved.