{-# LANGUAGE Safe #-}
#if __GLASGOW_HASKELL__ < 802
{-# OPTIONS_GHC -Wno-incomplete-patterns -Wno-incomplete-uni-patterns #-}
#endif

-- | Year quarters.
module Data.Time.Calendar.Quarter
    (
        QuarterOfYear(..), addQuarters, diffQuarters,
        Quarter(..),
        pattern YearQuarter,
        monthOfYearQuarter,
        monthQuarter,
        dayQuarter
    ) where

import Data.Time.Calendar.Types
import Data.Time.Calendar.Private
import Data.Time.Calendar.Days
import Data.Time.Calendar.Month
import Data.Data
import Data.Fixed
import Text.Read
import Text.ParserCombinators.ReadP
import Control.DeepSeq
import Data.Ix

-- | Quarters of each year. Each quarter corresponds to three months.
data QuarterOfYear = Q1 | Q2 | Q3 | Q4 deriving (QuarterOfYear -> QuarterOfYear -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QuarterOfYear -> QuarterOfYear -> Bool
$c/= :: QuarterOfYear -> QuarterOfYear -> Bool
== :: QuarterOfYear -> QuarterOfYear -> Bool
$c== :: QuarterOfYear -> QuarterOfYear -> Bool
Eq, Eq QuarterOfYear
QuarterOfYear -> QuarterOfYear -> Bool
QuarterOfYear -> QuarterOfYear -> Ordering
QuarterOfYear -> QuarterOfYear -> QuarterOfYear
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
$cmin :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
max :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
$cmax :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
>= :: QuarterOfYear -> QuarterOfYear -> Bool
$c>= :: QuarterOfYear -> QuarterOfYear -> Bool
> :: QuarterOfYear -> QuarterOfYear -> Bool
$c> :: QuarterOfYear -> QuarterOfYear -> Bool
<= :: QuarterOfYear -> QuarterOfYear -> Bool
$c<= :: QuarterOfYear -> QuarterOfYear -> Bool
< :: QuarterOfYear -> QuarterOfYear -> Bool
$c< :: QuarterOfYear -> QuarterOfYear -> Bool
compare :: QuarterOfYear -> QuarterOfYear -> Ordering
$ccompare :: QuarterOfYear -> QuarterOfYear -> Ordering
Ord, Typeable QuarterOfYear
QuarterOfYear -> DataType
QuarterOfYear -> Constr
(forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
forall u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QuarterOfYear
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QuarterOfYear)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QuarterOfYear)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
gmapT :: (forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear
$cgmapT :: (forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QuarterOfYear)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QuarterOfYear)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QuarterOfYear)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QuarterOfYear)
dataTypeOf :: QuarterOfYear -> DataType
$cdataTypeOf :: QuarterOfYear -> DataType
toConstr :: QuarterOfYear -> Constr
$ctoConstr :: QuarterOfYear -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QuarterOfYear
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QuarterOfYear
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear
Data, Typeable, ReadPrec [QuarterOfYear]
ReadPrec QuarterOfYear
Int -> ReadS QuarterOfYear
ReadS [QuarterOfYear]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [QuarterOfYear]
$creadListPrec :: ReadPrec [QuarterOfYear]
readPrec :: ReadPrec QuarterOfYear
$creadPrec :: ReadPrec QuarterOfYear
readList :: ReadS [QuarterOfYear]
$creadList :: ReadS [QuarterOfYear]
readsPrec :: Int -> ReadS QuarterOfYear
$creadsPrec :: Int -> ReadS QuarterOfYear
Read, Int -> QuarterOfYear -> ShowS
[QuarterOfYear] -> ShowS
QuarterOfYear -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QuarterOfYear] -> ShowS
$cshowList :: [QuarterOfYear] -> ShowS
show :: QuarterOfYear -> String
$cshow :: QuarterOfYear -> String
showsPrec :: Int -> QuarterOfYear -> ShowS
$cshowsPrec :: Int -> QuarterOfYear -> ShowS
Show, Ord QuarterOfYear
(QuarterOfYear, QuarterOfYear) -> Int
(QuarterOfYear, QuarterOfYear) -> [QuarterOfYear]
(QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Bool
(QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
forall a.
Ord a
-> ((a, a) -> [a])
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Int)
-> ((a, a) -> a -> Bool)
-> ((a, a) -> Int)
-> ((a, a) -> Int)
-> Ix a
unsafeRangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
$cunsafeRangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
rangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
$crangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
inRange :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Bool
$cinRange :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Bool
unsafeIndex :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
$cunsafeIndex :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
index :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
$cindex :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
range :: (QuarterOfYear, QuarterOfYear) -> [QuarterOfYear]
$crange :: (QuarterOfYear, QuarterOfYear) -> [QuarterOfYear]
Ix)

-- | maps Q1..Q4 to 1..4
instance Enum QuarterOfYear where
    toEnum :: Int -> QuarterOfYear
toEnum Int
i =
        case forall a. Real a => a -> a -> a
mod' Int
i Int
4 of
            Int
1 -> QuarterOfYear
Q1
            Int
2 -> QuarterOfYear
Q2
            Int
3 -> QuarterOfYear
Q3
            Int
_ -> QuarterOfYear
Q4
    fromEnum :: QuarterOfYear -> Int
fromEnum QuarterOfYear
Q1 = Int
1
    fromEnum QuarterOfYear
Q2 = Int
2
    fromEnum QuarterOfYear
Q3 = Int
3
    fromEnum QuarterOfYear
Q4 = Int
4

instance Bounded QuarterOfYear where
    minBound :: QuarterOfYear
minBound = QuarterOfYear
Q1
    maxBound :: QuarterOfYear
maxBound = QuarterOfYear
Q4

instance NFData QuarterOfYear where
    rnf :: QuarterOfYear -> ()
rnf QuarterOfYear
Q1 = ()
    rnf QuarterOfYear
Q2 = ()
    rnf QuarterOfYear
Q3 = ()
    rnf QuarterOfYear
Q4 = ()

-- | An absolute count of year quarters.
-- Number is equal to @(year * 4) + (quarterOfYear - 1)@.
newtype Quarter = MkQuarter Integer deriving (Quarter -> Quarter -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Quarter -> Quarter -> Bool
$c/= :: Quarter -> Quarter -> Bool
== :: Quarter -> Quarter -> Bool
$c== :: Quarter -> Quarter -> Bool
Eq, Eq Quarter
Quarter -> Quarter -> Bool
Quarter -> Quarter -> Ordering
Quarter -> Quarter -> Quarter
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: Quarter -> Quarter -> Quarter
$cmin :: Quarter -> Quarter -> Quarter
max :: Quarter -> Quarter -> Quarter
$cmax :: Quarter -> Quarter -> Quarter
>= :: Quarter -> Quarter -> Bool
$c>= :: Quarter -> Quarter -> Bool
> :: Quarter -> Quarter -> Bool
$c> :: Quarter -> Quarter -> Bool
<= :: Quarter -> Quarter -> Bool
$c<= :: Quarter -> Quarter -> Bool
< :: Quarter -> Quarter -> Bool
$c< :: Quarter -> Quarter -> Bool
compare :: Quarter -> Quarter -> Ordering
$ccompare :: Quarter -> Quarter -> Ordering
Ord, Typeable Quarter
Quarter -> DataType
Quarter -> Constr
(forall b. Data b => b -> b) -> Quarter -> Quarter
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u
forall u. (forall d. Data d => d -> u) -> Quarter -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Quarter
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quarter -> c Quarter
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Quarter)
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Quarter)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
$cgmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
$cgmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u
gmapQ :: forall u. (forall d. Data d => d -> u) -> Quarter -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Quarter -> [u]
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
$cgmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
gmapT :: (forall b. Data b => b -> b) -> Quarter -> Quarter
$cgmapT :: (forall b. Data b => b -> b) -> Quarter -> Quarter
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Quarter)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Quarter)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Quarter)
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Quarter)
dataTypeOf :: Quarter -> DataType
$cdataTypeOf :: Quarter -> DataType
toConstr :: Quarter -> Constr
$ctoConstr :: Quarter -> Constr
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Quarter
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Quarter
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quarter -> c Quarter
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quarter -> c Quarter
Data, Typeable)

instance NFData Quarter where
    rnf :: Quarter -> ()
rnf (MkQuarter Integer
m) = forall a. NFData a => a -> ()
rnf Integer
m

instance Enum Quarter where
    succ :: Quarter -> Quarter
succ (MkQuarter Integer
a) = Integer -> Quarter
MkQuarter (forall a. Enum a => a -> a
succ Integer
a)
    pred :: Quarter -> Quarter
pred (MkQuarter Integer
a) = Integer -> Quarter
MkQuarter (forall a. Enum a => a -> a
pred Integer
a)
    toEnum :: Int -> Quarter
toEnum = Integer -> Quarter
MkQuarter forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Enum a => Int -> a
toEnum
    fromEnum :: Quarter -> Int
fromEnum (MkQuarter Integer
a) = forall a. Enum a => a -> Int
fromEnum Integer
a
    enumFrom :: Quarter -> [Quarter]
enumFrom (MkQuarter Integer
a) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (forall a. Enum a => a -> [a]
enumFrom Integer
a)
    enumFromThen :: Quarter -> Quarter -> [Quarter]
enumFromThen (MkQuarter Integer
a) (MkQuarter Integer
b) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (forall a. Enum a => a -> a -> [a]
enumFromThen Integer
a Integer
b)
    enumFromTo :: Quarter -> Quarter -> [Quarter]
enumFromTo (MkQuarter Integer
a) (MkQuarter Integer
b) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (forall a. Enum a => a -> a -> [a]
enumFromTo Integer
a Integer
b)
    enumFromThenTo :: Quarter -> Quarter -> Quarter -> [Quarter]
enumFromThenTo (MkQuarter Integer
a) (MkQuarter Integer
b) (MkQuarter Integer
c) =
        forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (forall a. Enum a => a -> a -> a -> [a]
enumFromThenTo Integer
a Integer
b Integer
c)

instance Ix Quarter where
    range :: (Quarter, Quarter) -> [Quarter]
range (MkQuarter Integer
a, MkQuarter Integer
b) = forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (forall a. Ix a => (a, a) -> [a]
range (Integer
a, Integer
b))
    index :: (Quarter, Quarter) -> Quarter -> Int
index (MkQuarter Integer
a, MkQuarter Integer
b) (MkQuarter Integer
c) = forall a. Ix a => (a, a) -> a -> Int
index (Integer
a, Integer
b) Integer
c
    inRange :: (Quarter, Quarter) -> Quarter -> Bool
inRange (MkQuarter Integer
a, MkQuarter Integer
b) (MkQuarter Integer
c) = forall a. Ix a => (a, a) -> a -> Bool
inRange (Integer
a, Integer
b) Integer
c
    rangeSize :: (Quarter, Quarter) -> Int
rangeSize (MkQuarter Integer
a, MkQuarter Integer
b) = forall a. Ix a => (a, a) -> Int
rangeSize (Integer
a, Integer
b)

-- | Show as @yyyy-Qn@.
instance Show Quarter where
    show :: Quarter -> String
show (YearQuarter Integer
y QuarterOfYear
qy) = forall t. ShowPadded t => t -> String
show4 Integer
y forall a. [a] -> [a] -> [a]
++ String
"-" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show QuarterOfYear
qy

-- | Read as @yyyy-Qn@.
instance Read Quarter where
    readPrec :: ReadPrec Quarter
readPrec = do
        Integer
y <- forall a. Read a => ReadPrec a
readPrec
        Char
_ <- forall a. ReadP a -> ReadPrec a
lift forall a b. (a -> b) -> a -> b
$ Char -> ReadP Char
char Char
'-'
        QuarterOfYear
m <- forall a. Read a => ReadPrec a
readPrec
        forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Integer -> QuarterOfYear -> Quarter
YearQuarter Integer
y QuarterOfYear
m

addQuarters :: Integer -> Quarter -> Quarter
addQuarters :: Integer -> Quarter -> Quarter
addQuarters Integer
n (MkQuarter Integer
a) = Integer -> Quarter
MkQuarter forall a b. (a -> b) -> a -> b
$ Integer
a forall a. Num a => a -> a -> a
+ Integer
n

diffQuarters :: Quarter -> Quarter -> Integer
diffQuarters :: Quarter -> Quarter -> Integer
diffQuarters (MkQuarter Integer
a) (MkQuarter Integer
b) = Integer
a forall a. Num a => a -> a -> a
- Integer
b

-- | Bidirectional abstract constructor.
pattern YearQuarter :: Year -> QuarterOfYear -> Quarter
pattern $mYearQuarter :: forall {r}.
Quarter -> (Integer -> QuarterOfYear -> r) -> ((# #) -> r) -> r
$bYearQuarter :: Integer -> QuarterOfYear -> Quarter
YearQuarter y qy <- MkQuarter ((\Integer
q -> forall a b. (Real a, Integral b) => a -> a -> (b, a)
divMod' Integer
q Integer
4) -> (y,toEnum . succ . fromInteger -> qy)) where
    YearQuarter Integer
y QuarterOfYear
qy = Integer -> Quarter
MkQuarter forall a b. (a -> b) -> a -> b
$ (Integer
y forall a. Num a => a -> a -> a
* Integer
4) forall a. Num a => a -> a -> a
+ forall a. Integral a => a -> Integer
toInteger (forall a. Enum a => a -> a
pred forall a b. (a -> b) -> a -> b
$ forall a. Enum a => a -> Int
fromEnum QuarterOfYear
qy)

#if __GLASGOW_HASKELL__ >= 802
{-# COMPLETE YearQuarter #-}
#endif

monthOfYearQuarter :: MonthOfYear -> QuarterOfYear
monthOfYearQuarter :: Int -> QuarterOfYear
monthOfYearQuarter Int
my | Int
my forall a. Ord a => a -> a -> Bool
<= Int
3 = QuarterOfYear
Q1
monthOfYearQuarter Int
my | Int
my forall a. Ord a => a -> a -> Bool
<= Int
6 = QuarterOfYear
Q2
monthOfYearQuarter Int
my | Int
my forall a. Ord a => a -> a -> Bool
<= Int
9 = QuarterOfYear
Q3
monthOfYearQuarter Int
_ = QuarterOfYear
Q4

monthQuarter :: Month -> Quarter
monthQuarter :: Month -> Quarter
monthQuarter (YearMonth Integer
y Int
my) = Integer -> QuarterOfYear -> Quarter
YearQuarter Integer
y forall a b. (a -> b) -> a -> b
$ Int -> QuarterOfYear
monthOfYearQuarter Int
my

dayQuarter :: Day -> Quarter
dayQuarter :: Day -> Quarter
dayQuarter (MonthDay Month
m Int
_) = Month -> Quarter
monthQuarter Month
m