[commit: packages/time] master: fix week-based formatting chars, with more testing (f61178d)

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


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

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

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

commit f61178de5671ebf0006c0a9500f2b0f0d84da152
Author: Ashley Yakeley <ashley at semantic.org>
Date:   Tue May 10 03:33:55 2005 -0700

    fix week-based formatting chars, with more testing
    
    darcs-hash:20050510103355-ac6dd-319f78ca2b58fb5a381a9882cfa9727f3bfa465d


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

f61178de5671ebf0006c0a9500f2b0f0d84da152
 System/Time/Calendar/Format.hs | 13 ++++++++-----
 test/TestFormat.hs             | 14 ++++++--------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/System/Time/Calendar/Format.hs b/System/Time/Calendar/Format.hs
index eba951f..a3f08d3 100644
--- a/System/Time/Calendar/Format.hs
+++ b/System/Time/Calendar/Format.hs
@@ -79,14 +79,17 @@ weekDay day = fromInteger (mod (day + 3) 7)
 weekDay' :: ModJulianDay -> Int
 weekDay' day = weekDay (day - 1) + 1
 
-dayOfYear :: ModJulianDay -> Int
-dayOfYear = ydDay . encodeDay
-
 weekNumber :: ModJulianDay -> Int
-weekNumber day = (div (dayOfYear day) 7) + 1
+weekNumber mjd = fromInteger ((div d 7) - (div k 7)) where
+	yd = ydDay (encodeDay mjd)
+	d = mjd + 3
+	k = d - (toInteger yd)
 
 weekNumber' :: ModJulianDay -> Int
-weekNumber' day = (div (dayOfYear day) 7) + 1
+weekNumber' mjd = fromInteger ((div d 7) - (div k 7)) where
+	yd = ydDay (encodeDay mjd)
+	d = mjd + 2
+	k = d - (toInteger yd)
 
 instance FormatTime ModJulianDay where
 	-- Aggregate
diff --git a/test/TestFormat.hs b/test/TestFormat.hs
index 651df97..89ed600 100644
--- a/test/TestFormat.hs
+++ b/test/TestFormat.hs
@@ -65,7 +65,8 @@ getYearP4 :: Integer -> UTCTime
 getYearP4 year = decodeLocalUTC utc (CalendarTime (GregorianDay year 12 31) midnight)
 
 times :: [UTCTime]
-times = [baseTime0] ++ (fmap getDay [0..23])
+times = [baseTime0] ++ (fmap getDay [0..23]) ++ (fmap getDay [0..100]) ++
+	(fmap getYearP1 [1980..2000]) ++ (fmap getYearP2 [1980..2000]) ++ (fmap getYearP3 [1980..2000]) ++ (fmap getYearP4 [1980..2000])
 
 compareFormat :: String -> Timezone -> UTCTime -> IO ()
 compareFormat fmt zone time = let
@@ -83,11 +84,8 @@ compareFormat fmt zone time = let
 chars :: [Char]
 chars = "aAbBcCdDeFgGhHIjklmMnprRStTuUVwWxXyYzZ%"
 
+formats :: [String]
+formats =  ["%G-W%V-%u","%U-%w","%W-%u"] ++ (fmap (\char -> '%':char:[]) chars)
+
 main :: IO ()
-main = do
-	mapM_ (\day -> compareFormat "%G-W%V-%u" utc (getDay day)) [0..100]
-	mapM_ (\year -> compareFormat "%G-W%V-%u" utc (getYearP1 year)) [1980..2000]
-	mapM_ (\year -> compareFormat "%G-W%V-%u" utc (getYearP2 year)) [1980..2000]
-	mapM_ (\year -> compareFormat "%G-W%V-%u" utc (getYearP3 year)) [1980..2000]
-	mapM_ (\year -> compareFormat "%G-W%V-%u" utc (getYearP4 year)) [1980..2000]
-	mapM_ (\char -> let fmt = '%':char:[] in mapM_ (\time -> mapM_ (\zone -> compareFormat fmt zone time) zones) times) chars
+main = mapM_ (\fmt -> mapM_ (\time -> mapM_ (\zone -> compareFormat fmt zone time) zones) times) formats



More information about the ghc-commits mailing list