module Data.Time.Calendar.Week
(
DayOfWeek(..)
, dayOfWeek
) where
import Data.Time.Calendar.Days
data DayOfWeek
= Monday
| Tuesday
| Wednesday
| Thursday
| Friday
| Saturday
| Sunday
deriving (DayOfWeek -> DayOfWeek -> Bool
(DayOfWeek -> DayOfWeek -> Bool)
-> (DayOfWeek -> DayOfWeek -> Bool) -> Eq DayOfWeek
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DayOfWeek -> DayOfWeek -> Bool
$c/= :: DayOfWeek -> DayOfWeek -> Bool
== :: DayOfWeek -> DayOfWeek -> Bool
$c== :: DayOfWeek -> DayOfWeek -> Bool
Eq, Int -> DayOfWeek -> ShowS
[DayOfWeek] -> ShowS
DayOfWeek -> String
(Int -> DayOfWeek -> ShowS)
-> (DayOfWeek -> String)
-> ([DayOfWeek] -> ShowS)
-> Show DayOfWeek
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DayOfWeek] -> ShowS
$cshowList :: [DayOfWeek] -> ShowS
show :: DayOfWeek -> String
$cshow :: DayOfWeek -> String
showsPrec :: Int -> DayOfWeek -> ShowS
$cshowsPrec :: Int -> DayOfWeek -> ShowS
Show, ReadPrec [DayOfWeek]
ReadPrec DayOfWeek
Int -> ReadS DayOfWeek
ReadS [DayOfWeek]
(Int -> ReadS DayOfWeek)
-> ReadS [DayOfWeek]
-> ReadPrec DayOfWeek
-> ReadPrec [DayOfWeek]
-> Read DayOfWeek
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [DayOfWeek]
$creadListPrec :: ReadPrec [DayOfWeek]
readPrec :: ReadPrec DayOfWeek
$creadPrec :: ReadPrec DayOfWeek
readList :: ReadS [DayOfWeek]
$creadList :: ReadS [DayOfWeek]
readsPrec :: Int -> ReadS DayOfWeek
$creadsPrec :: Int -> ReadS DayOfWeek
Read)
instance Enum DayOfWeek where
toEnum :: Int -> DayOfWeek
toEnum Int
i =
case Int -> Int -> Int
forall a. Integral a => a -> a -> a
mod Int
i Int
7 of
Int
0 -> DayOfWeek
Sunday
Int
1 -> DayOfWeek
Monday
Int
2 -> DayOfWeek
Tuesday
Int
3 -> DayOfWeek
Wednesday
Int
4 -> DayOfWeek
Thursday
Int
5 -> DayOfWeek
Friday
Int
_ -> DayOfWeek
Saturday
fromEnum :: DayOfWeek -> Int
fromEnum DayOfWeek
Monday = Int
1
fromEnum DayOfWeek
Tuesday = Int
2
fromEnum DayOfWeek
Wednesday = Int
3
fromEnum DayOfWeek
Thursday = Int
4
fromEnum DayOfWeek
Friday = Int
5
fromEnum DayOfWeek
Saturday = Int
6
fromEnum DayOfWeek
Sunday = Int
7
enumFromTo :: DayOfWeek -> DayOfWeek -> [DayOfWeek]
enumFromTo DayOfWeek
wd1 DayOfWeek
wd2
| DayOfWeek
wd1 DayOfWeek -> DayOfWeek -> Bool
forall a. Eq a => a -> a -> Bool
== DayOfWeek
wd2 = [DayOfWeek
wd1]
enumFromTo DayOfWeek
wd1 DayOfWeek
wd2 = DayOfWeek
wd1 DayOfWeek -> [DayOfWeek] -> [DayOfWeek]
forall a. a -> [a] -> [a]
: DayOfWeek -> DayOfWeek -> [DayOfWeek]
forall a. Enum a => a -> a -> [a]
enumFromTo (DayOfWeek -> DayOfWeek
forall a. Enum a => a -> a
succ DayOfWeek
wd1) DayOfWeek
wd2
enumFromThenTo :: DayOfWeek -> DayOfWeek -> DayOfWeek -> [DayOfWeek]
enumFromThenTo DayOfWeek
wd1 DayOfWeek
wd2 DayOfWeek
wd3
| DayOfWeek
wd2 DayOfWeek -> DayOfWeek -> Bool
forall a. Eq a => a -> a -> Bool
== DayOfWeek
wd3 = [DayOfWeek
wd1, DayOfWeek
wd2]
enumFromThenTo DayOfWeek
wd1 DayOfWeek
wd2 DayOfWeek
wd3 = DayOfWeek
wd1 DayOfWeek -> [DayOfWeek] -> [DayOfWeek]
forall a. a -> [a] -> [a]
: DayOfWeek -> DayOfWeek -> DayOfWeek -> [DayOfWeek]
forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo DayOfWeek
wd2 (Int -> DayOfWeek
forall a. Enum a => Int -> a
toEnum (Int -> DayOfWeek) -> Int -> DayOfWeek
forall a b. (a -> b) -> a -> b
$ (Int
2 Int -> Int -> Int
forall a. Num a => a -> a -> a
* DayOfWeek -> Int
forall a. Enum a => a -> Int
fromEnum DayOfWeek
wd2) Int -> Int -> Int
forall a. Num a => a -> a -> a
- (DayOfWeek -> Int
forall a. Enum a => a -> Int
fromEnum DayOfWeek
wd1)) DayOfWeek
wd3
dayOfWeek :: Day -> DayOfWeek
dayOfWeek :: Day -> DayOfWeek
dayOfWeek (ModifiedJulianDay Integer
d) = Int -> DayOfWeek
forall a. Enum a => Int -> a
toEnum (Int -> DayOfWeek) -> Int -> DayOfWeek
forall a b. (a -> b) -> a -> b
$ Integer -> Int
forall a. Num a => Integer -> a
fromInteger (Integer -> Int) -> Integer -> Int
forall a b. (a -> b) -> a -> b
$ Integer
d Integer -> Integer -> Integer
forall a. Num a => a -> a -> a
+ Integer
3