[commit: packages/time] format-widths, ghc, master, tasty: POSIX: clean up definitions, fix posixToUTCTime (255aa53)
git at git.haskell.org
git at git.haskell.org
Fri Apr 21 16:55:41 UTC 2017
Repository : ssh://git@git.haskell.org/time
On branches: format-widths,ghc,master,tasty
Link : http://git.haskell.org/packages/time.git/commitdiff/255aa53abdf6119a2e764de04ab88bdbffec9b4c
>---------------------------------------------------------------
commit 255aa53abdf6119a2e764de04ab88bdbffec9b4c
Author: Ashley Yakeley <ashley at yakeley.org>
Date: Tue Dec 6 23:03:00 2016 -0800
POSIX: clean up definitions, fix posixToUTCTime
>---------------------------------------------------------------
255aa53abdf6119a2e764de04ab88bdbffec9b4c
lib/Data/Time/Clock/POSIX.hs | 22 ++++++++--------------
1 file changed, 8 insertions(+), 14 deletions(-)
diff --git a/lib/Data/Time/Clock/POSIX.hs b/lib/Data/Time/Clock/POSIX.hs
index 94bc8ee..82d18fd 100644
--- a/lib/Data/Time/Clock/POSIX.hs
+++ b/lib/Data/Time/Clock/POSIX.hs
@@ -2,7 +2,7 @@
-- Most people won't need this module.
module Data.Time.Clock.POSIX
(
- posixDayLength,POSIXTime,
+ POSIXTime,
makePOSIXTime,ptSeconds,ptNanoSeconds,
posixSecondsToUTCTime,utcTimeToPOSIXSeconds,
posixToUTCTime,getPOSIXTime,getCurrentTime
@@ -71,14 +71,11 @@ instance NFData POSIXTime where
rnf a = a `seq` ()
posixToUTCTime :: POSIXTime -> UTCTime
-posixToUTCTime (POSIXTime s ns) =
- let (d, s') = s `divMod` posixDayLength
- ps = s' * 1000000000000 + fromIntegral (ns * 1000) -- 'Int64' can hold ps in one day
- in UTCTime (addDays (fromIntegral d) unixEpochDay)
- (picosecondsToDiffTime (fromIntegral ps))
-
-posixDayLength :: Int64
-posixDayLength = 86400
+posixToUTCTime (POSIXTime s ns) = let
+ (d, s') = s `divMod` 86400
+ ps :: Int64
+ ps = s' * 1000000000000 + (fromIntegral ns) * 1000
+ in UTCTime (addDays (fromIntegral d) unixEpochDay) (picosecondsToDiffTime $ fromIntegral ps)
unixEpochDay :: Day
unixEpochDay = ModifiedJulianDay 40587
@@ -115,17 +112,14 @@ getPOSIXTime = do
--------------------------------------------------------------------------------
-posixDayLength_ :: NominalDiffTime
-posixDayLength_ = 86400
-
posixSecondsToUTCTime :: NominalDiffTime -> UTCTime
posixSecondsToUTCTime i = let
- (d,t) = divMod' i posixDayLength_
+ (d,t) = divMod' i nominalDay
in UTCTime (addDays d unixEpochDay) (realToFrac t)
utcTimeToPOSIXSeconds :: UTCTime -> NominalDiffTime
utcTimeToPOSIXSeconds (UTCTime d t) =
- (fromInteger (diffDays d unixEpochDay) * posixDayLength_) + min posixDayLength_ (realToFrac t)
+ (fromInteger (diffDays d unixEpochDay) * nominalDay) + min nominalDay (realToFrac t)
-- | Get the current 'UTCTime' from the system clock.
getCurrentTime :: IO UTCTime
More information about the ghc-commits
mailing list