[commit: packages/time] master: Handle 'c' also in formatTime for ZonedTime, to get %Z filled in for ZonedTime and UTCTime. (573daed)

git at git.haskell.org git at git.haskell.org
Fri Jan 23 22:57:03 UTC 2015


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

On branch  : master
Link       : http://git.haskell.org/packages/time.git/commitdiff/573daed43a143ea75360c23317ec9efebe01dfe5

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

commit 573daed43a143ea75360c23317ec9efebe01dfe5
Author: bjorn <bjorn at bringert.net>
Date:   Wed Nov 15 14:08:18 2006 -0800

    Handle 'c' also in formatTime for ZonedTime, to get %Z filled in for ZonedTime and UTCTime.
    
    Before, formatTime "%c" did not include the time zone even when applied to ZonedTime or UTCTime,
    since "%c" was handled by the FormatTime LocalTime instance:
    
    > fmap (formatTime System.Locale.defaultTimeLocale "%c") getZonedTime
    "Sat Nov 11 19:12:45.395568  2006"
    > fmap (formatTime System.Locale.defaultTimeLocale "%c") getCurrentTime
    "Sat Nov 11 18:13:52.010944  2006"
    
    Now it is correct:
    
    > fmap (formatTime System.Locale.defaultTimeLocale "%c") getZonedTime
    "Wed Nov 15 23:08:43.987526 CET 2006"
    > fmap (formatTime System.Locale.defaultTimeLocale "%c") getCurrentTime
    "Wed Nov 15 22:08:51.530603 UTC 2006"
    
    darcs-hash:20061115220818-6cdb2-db20654b473141486d86a09551688043eebafb8b


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

573daed43a143ea75360c23317ec9efebe01dfe5
 Data/Time/LocalTime/Format.hs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Data/Time/LocalTime/Format.hs b/Data/Time/LocalTime/Format.hs
index d817c13..c13160e 100644
--- a/Data/Time/LocalTime/Format.hs
+++ b/Data/Time/LocalTime/Format.hs
@@ -160,6 +160,7 @@ instance FormatTime TimeOfDay where
 	formatCharacter _   = Nothing
 
 instance FormatTime ZonedTime where
+	formatCharacter 'c' = Just (\locale -> formatTime locale (dateTimeFmt locale))
 	formatCharacter 's' = Just (\_ zt -> show (truncate (utcTimeToPOSIXSeconds (zonedTimeToUTC zt)) :: Integer))
 	formatCharacter c = case (formatCharacter c) of
 		Just f -> Just (\locale dt -> f locale (zonedTimeToLocalTime dt))



More information about the ghc-commits mailing list