format everything with hindent
[packages/time.git] / lib / Data / Time / Calendar / Days.hs
1 {-# OPTIONS -fno-warn-unused-imports #-}
2
3 module Data.Time.Calendar.Days
4 (
5 -- * Days
6 Day(..)
7 , addDays
8 , diffDays
9 ) where
10
11 import Control.DeepSeq
12 import Data.Data
13 import Data.Ix
14 import Data.Typeable
15
16 -- | The Modified Julian Day is a standard count of days, with zero being the day 1858-11-17.
17 newtype Day = ModifiedJulianDay
18 { toModifiedJulianDay :: Integer
19 } deriving (Eq, Ord, Data, Typeable)
20
21 instance NFData Day where
22 rnf (ModifiedJulianDay a) = rnf a
23
24 -- necessary because H98 doesn't have "cunning newtype" derivation
25 instance Enum Day where
26 succ (ModifiedJulianDay a) = ModifiedJulianDay (succ a)
27 pred (ModifiedJulianDay a) = ModifiedJulianDay (pred a)
28 toEnum = ModifiedJulianDay . toEnum
29 fromEnum (ModifiedJulianDay a) = fromEnum a
30 enumFrom (ModifiedJulianDay a) = fmap ModifiedJulianDay (enumFrom a)
31 enumFromThen (ModifiedJulianDay a) (ModifiedJulianDay b) = fmap ModifiedJulianDay (enumFromThen a b)
32 enumFromTo (ModifiedJulianDay a) (ModifiedJulianDay b) = fmap ModifiedJulianDay (enumFromTo a b)
33 enumFromThenTo (ModifiedJulianDay a) (ModifiedJulianDay b) (ModifiedJulianDay c) =
34 fmap ModifiedJulianDay (enumFromThenTo a b c)
35
36 -- necessary because H98 doesn't have "cunning newtype" derivation
37 instance Ix Day where
38 range (ModifiedJulianDay a, ModifiedJulianDay b) = fmap ModifiedJulianDay (range (a, b))
39 index (ModifiedJulianDay a, ModifiedJulianDay b) (ModifiedJulianDay c) = index (a, b) c
40 inRange (ModifiedJulianDay a, ModifiedJulianDay b) (ModifiedJulianDay c) = inRange (a, b) c
41 rangeSize (ModifiedJulianDay a, ModifiedJulianDay b) = rangeSize (a, b)
42
43 addDays :: Integer -> Day -> Day
44 addDays n (ModifiedJulianDay a) = ModifiedJulianDay (a + n)
45
46 diffDays :: Day -> Day -> Integer
47 diffDays (ModifiedJulianDay a) (ModifiedJulianDay b) = a - b