[commit: packages/time] master: add %s format option to ZonedTime (18b9d5a)

git at git.haskell.org git at git.haskell.org
Sun Dec 20 07:46:41 UTC 2015


Repository : ssh://git@git.haskell.org/time

On branch  : master
Link       : http://git.haskell.org/packages/time.git/commitdiff/18b9d5aea26a1701d120f0003fbae80b3739a577

>---------------------------------------------------------------

commit 18b9d5aea26a1701d120f0003fbae80b3739a577
Author: ashley <ashley at semantic.org>
Date:   Wed May 4 01:15:17 2005 -0700

    add %s format option to ZonedTime
    
    darcs-hash:20050504081517-ca2d0-1e7afb6180a65e6451b094468b1ae503acc8469b


>---------------------------------------------------------------

18b9d5aea26a1701d120f0003fbae80b3739a577
 System/Time/Calendar/Calendar.hs | 3 ++-
 TestFormat.hs                    | 7 +++++--
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/System/Time/Calendar/Calendar.hs b/System/Time/Calendar/Calendar.hs
index c0bc502..9283094 100644
--- a/System/Time/Calendar/Calendar.hs
+++ b/System/Time/Calendar/Calendar.hs
@@ -85,6 +85,7 @@ decodeUTC (ZonedTime t zone) = decodeLocalUTC zone t
 instance (Show t) => Show (ZonedTime t) where
 	show (ZonedTime t zone) = show t ++ " " ++ show zone
 
-instance (FormatTime t) => FormatTime (ZonedTime t) where
+instance (FormatTime t,LocalTimeEncoding t) => FormatTime (ZonedTime t) where
+	formatCharacter _ 's' zt = Just (show (truncate (utcTimeToPOSIXSeconds (decodeUTC zt)) :: Integer))
 	formatCharacter locale c (ZonedTime t zone) = 
 		melse (formatCharacter locale c t) (formatCharacter locale c zone)
diff --git a/TestFormat.hs b/TestFormat.hs
index 34c9892..e3f2728 100644
--- a/TestFormat.hs
+++ b/TestFormat.hs
@@ -38,11 +38,14 @@ zones = [utc,hoursToTimezone (- 7)]
 posixDay :: UTCDiffTime
 posixDay = 86400
 
+baseTime0 :: UTCTime
+baseTime0 = decodeLocalUTC utc (CalendarTime (GregorianDay 1970 01 01) midnight)
+
 baseTime1 :: UTCTime
 baseTime1 = decodeLocalUTC utc (CalendarTime (GregorianDay 2005 05 01) midnight)
 
 times :: [UTCTime]
-times = [baseTime1,addUTCTime posixDay baseTime1,addUTCTime (2 * posixDay) baseTime1]
+times = [baseTime0,baseTime1,addUTCTime posixDay baseTime1,addUTCTime (2 * posixDay) baseTime1]
 
 -- as found in http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
 -- plus FgGklPsz
@@ -56,5 +59,5 @@ main = mapM_ (\char -> let fmt = '%':char:[] in mapM_ (\time -> mapM_ (\zone ->
 	in do
 		unixText <- unixFormatTime fmt zone time
 		if haskellText == unixText then return () else
-			putStrLn ("Mismatch with " ++ fmt ++ " for " ++ (show ctime) ++ " " ++ (show zone) ++ ": UNIX says \"" ++ unixText ++ "\", TimeLib says \"" ++ haskellText ++ "\".")
+			putStrLn ("Mismatch with " ++ fmt ++ " for " ++ (show ctime) ++ ": UNIX says \"" ++ unixText ++ "\", TimeLib says \"" ++ haskellText ++ "\".")
 	) zones) times) chars



More information about the ghc-commits mailing list