[commit: packages/time] format-widths, master, tasty: faster getCurrentTimeZone (a6cedc9)
git at git.haskell.org
git at git.haskell.org
Mon Feb 20 21:19:24 UTC 2017
Repository : ssh://git@git.haskell.org/time
On branches: format-widths,master,tasty
Link : http://git.haskell.org/packages/time.git/commitdiff/a6cedc964f87279296557060dd8b361a87e75a96
>---------------------------------------------------------------
commit a6cedc964f87279296557060dd8b361a87e75a96
Author: Ashley Yakeley <ashley at yakeley.org>
Date: Mon Dec 12 22:51:23 2016 -0800
faster getCurrentTimeZone
>---------------------------------------------------------------
a6cedc964f87279296557060dd8b361a87e75a96
lib/Data/Time/LocalTime/TimeZone.hs | 20 ++++++++++++--------
1 file changed, 12 insertions(+), 8 deletions(-)
diff --git a/lib/Data/Time/LocalTime/TimeZone.hs b/lib/Data/Time/LocalTime/TimeZone.hs
index b876556..c77c9e7 100644
--- a/lib/Data/Time/LocalTime/TimeZone.hs
+++ b/lib/Data/Time/LocalTime/TimeZone.hs
@@ -79,13 +79,9 @@ utc = TimeZone 0 False "UTC"
{-# CFILES cbits/HsTime.c #-}
foreign import ccall unsafe "HsTime.h get_current_timezone_seconds" get_current_timezone_seconds :: CTime -> Ptr CInt -> Ptr CString -> IO CLong
-posixToCTime :: NominalDiffTime -> CTime
-posixToCTime = fromInteger . floor
-
--- | Get the local time-zone for a given time (varying as per summertime adjustments)
-getTimeZone :: UTCTime -> IO TimeZone
-getTimeZone time = with 0 (\pdst -> with nullPtr (\pcname -> do
- secs <- get_current_timezone_seconds (posixToCTime (utcTimeToPOSIXSeconds time)) pdst pcname
+getTimeZoneCTime :: CTime -> IO TimeZone
+getTimeZoneCTime ctime = with 0 (\pdst -> with nullPtr (\pcname -> do
+ secs <- get_current_timezone_seconds ctime pdst pcname
case secs of
0x80000000 -> fail "localtime_r failed"
_ -> do
@@ -95,6 +91,14 @@ getTimeZone time = with 0 (\pdst -> with nullPtr (\pcname -> do
return (TimeZone (div (fromIntegral secs) 60) (dst == 1) name)
))
+-- | Get the local time-zone for a given time (varying as per summertime adjustments)
+getTimeZonePosix :: POSIXTime -> IO TimeZone
+getTimeZonePosix = getTimeZoneCTime . CTime . ptSeconds
+
+-- | Get the local time-zone for a given time (varying as per summertime adjustments)
+getTimeZone :: UTCTime -> IO TimeZone
+getTimeZone = getTimeZoneCTime . fromInteger . floor . utcTimeToPOSIXSeconds
+
-- | Get the current time-zone
getCurrentTimeZone :: IO TimeZone
-getCurrentTimeZone = getCurrentTime >>= getTimeZone
+getCurrentTimeZone = getPOSIXTime >>= getTimeZonePosix
More information about the ghc-commits
mailing list