[commit: packages/time] master: add GNU and other extensions to formatting (ce92c0a)

git at git.haskell.org git at git.haskell.org
Fri Jan 23 22:53:32 UTC 2015


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

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

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

commit ce92c0a6f8d88ab2f1aa6de6dce271b1d790ce1b
Author: Ashley Yakeley <ashley at semantic.org>
Date:   Sun May 1 05:08:16 2005 -0700

    add GNU and other extensions to formatting
    
    darcs-hash:20050501120816-ac6dd-b30e46bc30c5fae816095c2f154ea9cb5ee3c3f8


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

ce92c0a6f8d88ab2f1aa6de6dce271b1d790ce1b
 System/Time/Calendar/Gregorian.hs | 12 +++++++++---
 System/Time/Calendar/TimeOfDay.hs |  7 ++++++-
 TestFormat.hs                     |  3 ++-
 3 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/System/Time/Calendar/Gregorian.hs b/System/Time/Calendar/Gregorian.hs
index 3d0dcce..b10c509 100644
--- a/System/Time/Calendar/Gregorian.hs
+++ b/System/Time/Calendar/Gregorian.hs
@@ -39,8 +39,11 @@ weekNumber day = (div (dayOfYear day) 7) + 1
 weekNumber' :: ModJulianDay -> Int
 weekNumber' day = (div (dayOfYear day) 7) + 1
 
-weekNumber'' :: ModJulianDay -> Int
-weekNumber'' day = (div (dayOfYear day) 7) + 1
+isoWeekFormat :: ModJulianDay -> (Integer,Int,Int)
+isoWeekFormat day = (y,div k 7,fromInteger (mod day 7) + 1) where
+	(year,yd,_) = dayToYearDay day
+	k = yd -- WRONG
+	y = year -- WRONG
 
 instance FormatTime GregorianDay where
 	formatCharacter locale 'a' day = Just (snd ((wDays locale) !! (weekDay (calendarToDay day))))
@@ -51,12 +54,15 @@ instance FormatTime GregorianDay where
 	formatCharacter _ 'd' (GregorianDay _ _ d) = Just (show2 d)
 	formatCharacter locale 'D' day = Just (formatTime locale "%m/%d/%y" day)
 	formatCharacter _ 'e' (GregorianDay _ _ d) = Just (show2Space d)
+	formatCharacter locale 'F' day = Just (formatTime locale "%Y-%m-%d" day)
+	formatCharacter _ 'g' day = let (y,_,_) = isoWeekFormat (calendarToDay day) in Just (show2 (fromInteger (mod y 100)))
+	formatCharacter _ 'G' day = let (y,_,_) = isoWeekFormat (calendarToDay day) in Just (show y)
 	formatCharacter locale 'h' (GregorianDay _ m _) = Just (snd ((months locale) !! (m - 1)))
 	formatCharacter _ 'j' day = Just (show3 (dayOfYear (calendarToDay day)))
 	formatCharacter _ 'm' (GregorianDay _ m _) = Just (show2 m)
 	formatCharacter _ 'u' day = Just (show (weekDay' (calendarToDay day)))
 	formatCharacter _ 'U' day = Just (show2 (weekNumber (calendarToDay day)))
-	formatCharacter _ 'V' day = Just (show2 (weekNumber'' (calendarToDay day)))
+	formatCharacter _ 'V' day = let (_,n,_) = isoWeekFormat (calendarToDay day) in Just (show2 n)
 	formatCharacter _ 'w' day = Just (show (weekDay (calendarToDay day)))
 	formatCharacter _ 'W' day = Just (show2 (weekNumber' (calendarToDay day)))
 	formatCharacter locale 'x' day = Just (formatTime locale (dateFmt locale) day)
diff --git a/System/Time/Calendar/TimeOfDay.hs b/System/Time/Calendar/TimeOfDay.hs
index 17cdc93..ba1c891 100644
--- a/System/Time/Calendar/TimeOfDay.hs
+++ b/System/Time/Calendar/TimeOfDay.hs
@@ -12,9 +12,11 @@ import System.Time.Calendar.Timezone
 import System.Time.Calendar.Format
 import System.Time.Calendar.Private
 import System.Time.Clock
-import System.Locale
 import Data.Fixed
 
+import System.Locale
+import Data.Char
+
 -- | time of day as represented in hour, minute and second (with picoseconds), typically used to express local time of day
 data TimeOfDay = TimeOfDay {
 	todHour    :: Int,
@@ -34,8 +36,11 @@ instance Show TimeOfDay where
 instance FormatTime TimeOfDay where
 	formatCharacter _ 'H' (TimeOfDay h _ _) = Just (show2 h)
 	formatCharacter _ 'I' (TimeOfDay h _ _) = Just (show2 ((mod (h - 1) 12) + 1))
+	formatCharacter _ 'k' (TimeOfDay h _ _) = Just (show2Space h)
+	formatCharacter _ 'l' (TimeOfDay h _ _) = Just (show2Space ((mod (h - 1) 12) + 1))
 	formatCharacter _ 'M' (TimeOfDay _ m _) = Just (show2 m)
 	formatCharacter locale 'p' (TimeOfDay h _ _) = Just ((if h < 12 then fst else snd) (amPm locale))
+	formatCharacter locale 'P' (TimeOfDay h _ _) = Just (map toLower ((if h < 12 then fst else snd) (amPm locale)))
 	formatCharacter locale 'r' time = Just (formatTime locale (time12Fmt locale) time)
 	formatCharacter locale 'R' time = Just (formatTime locale "%H:%M" time)
 	formatCharacter _ 'S' (TimeOfDay _ _ s) = Just (show2Fixed s)
diff --git a/TestFormat.hs b/TestFormat.hs
index 4d7f800..8534c77 100644
--- a/TestFormat.hs
+++ b/TestFormat.hs
@@ -45,8 +45,9 @@ times :: [UTCTime]
 times = [baseTime1,addUTCTime posixDay baseTime1,addUTCTime (2 * posixDay) baseTime1]
 
 -- as found in http://www.opengroup.org/onlinepubs/007908799/xsh/strftime.html
+-- plus FgGklPsz
 chars :: [Char]
-chars = "aAbBcCdDehHIjmMnprRStTuUVwWxXyYzZ%"
+chars = "aAbBcCdDeFgGhHIjklmMnpPrRsStTuUVwWxXyYzZ%"
 
 main :: IO ()
 main = mapM_ (\char -> let fmt = '%':char:[] in mapM_ (\time -> mapM_ (\zone -> let



More information about the ghc-commits mailing list