[commit: packages/time] format-widths, improve-leapseconds, master, posix-perf, tasty, wip/travis: organise week functions (73c160c)
git at git.haskell.org
git at git.haskell.org
Mon Feb 20 21:08:17 UTC 2017
- Previous message: [commit: packages/time] format-widths, improve-leapseconds, master, posix-perf, tasty, wip/travis: fix week-based formatting chars, with more testing (f61178d)
- Next message: [commit: packages/time] format-widths, improve-leapseconds, master, posix-perf, tasty, wip/travis: clean up some type names, more doc (23be1cb)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
Repository : ssh://git@git.haskell.org/time
On branches: format-widths,improve-leapseconds,master,posix-perf,tasty,wip/travis
Link : http://git.haskell.org/packages/time.git/commitdiff/73c160cf9cb8289b041389470d38afaacbd31387
>---------------------------------------------------------------
commit 73c160cf9cb8289b041389470d38afaacbd31387
Author: Ashley Yakeley <ashley at semantic.org>
Date: Tue May 10 04:03:21 2005 -0700
organise week functions
darcs-hash:20050510110321-ac6dd-405622ed76952493da885fb866043a8d247ac06c
>---------------------------------------------------------------
73c160cf9cb8289b041389470d38afaacbd31387
Makefile | 1 +
System/Time/Calendar/Format.hs | 28 +++++-----------------------
System/Time/Calendar/YearDay.hs | 19 +++++++++++++++++++
3 files changed, 25 insertions(+), 23 deletions(-)
diff --git a/Makefile b/Makefile
index c6c6b0b..36a93b7 100644
--- a/Makefile
+++ b/Makefile
@@ -82,6 +82,7 @@ System/Time/Calendar/Calendar.o : System/Time/Clock.hi
System/Time/Calendar/Calendar.o : System/Time/Calendar/Timezone.hi
System/Time/Calendar/Calendar.o : System/Time/Calendar/TimeOfDay.hi
System/Time/Calendar/YearDay.o : System/Time/Calendar/YearDay.hs
+System/Time/Calendar/YearDay.o : System/Time/Clock.hi
System/Time/Calendar/YearDay.o : System/Time/Calendar/Private.hi
System/Time/Calendar/YearDay.o : System/Time/Calendar/Calendar.hi
System/Time/Calendar/Gregorian.o : System/Time/Calendar/Gregorian.hs
diff --git a/System/Time/Calendar/Format.hs b/System/Time/Calendar/Format.hs
index a3f08d3..398c4c0 100644
--- a/System/Time/Calendar/Format.hs
+++ b/System/Time/Calendar/Format.hs
@@ -73,24 +73,6 @@ instance FormatTime Timezone where
formatCharacter 'Z' = Just (\_ -> timezoneName)
formatCharacter _ = Nothing
-weekDay :: ModJulianDay -> Int
-weekDay day = fromInteger (mod (day + 3) 7)
-
-weekDay' :: ModJulianDay -> Int
-weekDay' day = weekDay (day - 1) + 1
-
-weekNumber :: ModJulianDay -> Int
-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' 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
formatCharacter 'D' = Just (\locale -> formatTime locale "%m/%d/%y")
@@ -119,11 +101,11 @@ instance FormatTime ModJulianDay where
formatCharacter 'u' = Just (\_ -> show . isowDay . encodeDay)
-- Day of week
- formatCharacter 'a' = Just (\locale -> snd . ((wDays locale) !!) . weekDay)
- formatCharacter 'A' = Just (\locale -> fst . ((wDays locale) !!) . weekDay)
- formatCharacter 'U' = Just (\_ -> show2 . weekNumber)
- formatCharacter 'w' = Just (\_ -> show . weekDay)
- formatCharacter 'W' = Just (\_ -> show2 . weekNumber')
+ formatCharacter 'a' = Just (\locale -> snd . ((wDays locale) !!) . snd . sundayStartWeek)
+ formatCharacter 'A' = Just (\locale -> fst . ((wDays locale) !!) . snd . sundayStartWeek)
+ formatCharacter 'U' = Just (\_ -> show2 . fst . sundayStartWeek)
+ formatCharacter 'w' = Just (\_ -> show . snd . sundayStartWeek)
+ formatCharacter 'W' = Just (\_ -> show2 . fst . mondayStartWeek)
-- Default
formatCharacter _ = Nothing
diff --git a/System/Time/Calendar/YearDay.hs b/System/Time/Calendar/YearDay.hs
index 556c913..2c120eb 100644
--- a/System/Time/Calendar/YearDay.hs
+++ b/System/Time/Calendar/YearDay.hs
@@ -4,6 +4,7 @@ module System.Time.Calendar.YearDay where
import System.Time.Calendar.Calendar
import System.Time.Calendar.Private
+import System.Time.Clock
-- | ISO 8601 Ordinal Date
data YearDay = YearDay {
@@ -32,3 +33,21 @@ instance DayEncoding YearDay where
isLeapYear :: Integer -> Bool
isLeapYear year = (mod year 4 == 0) && ((mod year 400 == 0) || not (mod year 100 == 0))
+
+-- | Get the number of the Monday-starting week in the year and the day of the week.
+-- The first Monday is the first day of week 1, any earlier days in the year are week 0 (as \"%W\" in formatTime).
+-- Monday is 1, Sunday is 7 (as \"%u\" in formatTime).
+mondayStartWeek :: ModJulianDay -> (Int,Int)
+mondayStartWeek mjd =(fromInteger ((div d 7) - (div k 7)),fromInteger (mod d 7) + 1) where
+ yd = ydDay (encodeDay mjd)
+ d = mjd + 2
+ k = d - (toInteger yd)
+
+-- | Get the number of the Sunday-starting week in the year and the day of the week.
+-- The first Sunday is the first day of week 1, any earlier days in the year are week 0 (as \"%U\" in formatTime).
+-- Sunday is 0, Saturday is 6 (as \"%w\" in formatTime).
+sundayStartWeek :: ModJulianDay -> (Int,Int)
+sundayStartWeek mjd =(fromInteger ((div d 7) - (div k 7)),fromInteger (mod d 7)) where
+ yd = ydDay (encodeDay mjd)
+ d = mjd + 3
+ k = d - (toInteger yd)
- Previous message: [commit: packages/time] format-widths, improve-leapseconds, master, posix-perf, tasty, wip/travis: fix week-based formatting chars, with more testing (f61178d)
- Next message: [commit: packages/time] format-widths, improve-leapseconds, master, posix-perf, tasty, wip/travis: clean up some type names, more doc (23be1cb)
- Messages sorted by:
[ date ]
[ thread ]
[ subject ]
[ author ]
More information about the ghc-commits
mailing list