{-# LANGUAGE Safe #-}

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

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

-- | Quarters of each year. Each quarter corresponds to three months.
data QuarterOfYear = Q1 | Q2 | Q3 | Q4 deriving (QuarterOfYear -> QuarterOfYear -> Bool
(QuarterOfYear -> QuarterOfYear -> Bool)
-> (QuarterOfYear -> QuarterOfYear -> Bool) -> Eq QuarterOfYear
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
Eq QuarterOfYear
-> (QuarterOfYear -> QuarterOfYear -> Ordering)
-> (QuarterOfYear -> QuarterOfYear -> Bool)
-> (QuarterOfYear -> QuarterOfYear -> Bool)
-> (QuarterOfYear -> QuarterOfYear -> Bool)
-> (QuarterOfYear -> QuarterOfYear -> Bool)
-> (QuarterOfYear -> QuarterOfYear -> QuarterOfYear)
-> (QuarterOfYear -> QuarterOfYear -> QuarterOfYear)
-> Ord 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
$cp1Ord :: Eq QuarterOfYear
Ord, Typeable QuarterOfYear
DataType
Constr
Typeable QuarterOfYear
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c QuarterOfYear)
-> (QuarterOfYear -> Constr)
-> (QuarterOfYear -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear)
-> (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 u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear)
-> Data QuarterOfYear
QuarterOfYear -> DataType
QuarterOfYear -> Constr
(forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cQ4 :: Constr
$cQ3 :: Constr
$cQ2 :: Constr
$cQ1 :: Constr
$tQuarterOfYear :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
gmapQ :: (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable QuarterOfYear
Data, Typeable, ReadPrec [QuarterOfYear]
ReadPrec QuarterOfYear
Int -> ReadS QuarterOfYear
ReadS [QuarterOfYear]
(Int -> ReadS QuarterOfYear)
-> ReadS [QuarterOfYear]
-> ReadPrec QuarterOfYear
-> ReadPrec [QuarterOfYear]
-> Read 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
(Int -> QuarterOfYear -> ShowS)
-> (QuarterOfYear -> String)
-> ([QuarterOfYear] -> ShowS)
-> Show QuarterOfYear
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
Ord QuarterOfYear
-> ((QuarterOfYear, QuarterOfYear) -> [QuarterOfYear])
-> ((QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int)
-> ((QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int)
-> ((QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Bool)
-> ((QuarterOfYear, QuarterOfYear) -> Int)
-> ((QuarterOfYear, QuarterOfYear) -> Int)
-> Ix 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]
$cp1Ix :: Ord QuarterOfYear
Ix)

-- | maps Q1..Q4 to 1..4
instance Enum QuarterOfYear where
    toEnum :: Int -> QuarterOfYear
toEnum Int
i =
        case Int -> Int -> Int
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
(Quarter -> Quarter -> Bool)
-> (Quarter -> Quarter -> Bool) -> Eq Quarter
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
Eq Quarter
-> (Quarter -> Quarter -> Ordering)
-> (Quarter -> Quarter -> Bool)
-> (Quarter -> Quarter -> Bool)
-> (Quarter -> Quarter -> Bool)
-> (Quarter -> Quarter -> Bool)
-> (Quarter -> Quarter -> Quarter)
-> (Quarter -> Quarter -> Quarter)
-> Ord 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
$cp1Ord :: Eq Quarter
Ord, Typeable Quarter
DataType
Constr
Typeable Quarter
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> Quarter -> c Quarter)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c Quarter)
-> (Quarter -> Constr)
-> (Quarter -> DataType)
-> (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))
-> ((forall b. Data b => b -> b) -> Quarter -> Quarter)
-> (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 u. (forall d. Data d => d -> u) -> Quarter -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u)
-> (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 (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> Quarter -> m Quarter)
-> Data Quarter
Quarter -> DataType
Quarter -> Constr
(forall b. Data b => b -> b) -> Quarter -> Quarter
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quarter -> c Quarter
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c 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)
$cMkQuarter :: Constr
$tQuarter :: DataType
gmapMo :: (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 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 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 :: Int -> (forall d. Data d => d -> u) -> Quarter -> u
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u
gmapQ :: (forall d. Data d => d -> u) -> Quarter -> [u]
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Quarter -> [u]
gmapQr :: (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 :: (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 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 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 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 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
$cp1Data :: Typeable Quarter
Data, Typeable)

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

instance Enum Quarter where
    succ :: Quarter -> Quarter
succ (MkQuarter Integer
a) = Integer -> Quarter
MkQuarter (Integer -> Integer
forall a. Enum a => a -> a
succ Integer
a)
    pred :: Quarter -> Quarter
pred (MkQuarter Integer
a) = Integer -> Quarter
MkQuarter (Integer -> Integer
forall a. Enum a => a -> a
pred Integer
a)
    toEnum :: Int -> Quarter
toEnum = Integer -> Quarter
MkQuarter (Integer -> Quarter) -> (Int -> Integer) -> Int -> Quarter
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Integer
forall a. Enum a => Int -> a
toEnum
    fromEnum :: Quarter -> Int
fromEnum (MkQuarter Integer
a) = Integer -> Int
forall a. Enum a => a -> Int
fromEnum Integer
a
    enumFrom :: Quarter -> [Quarter]
enumFrom (MkQuarter Integer
a) = (Integer -> Quarter) -> [Integer] -> [Quarter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (Integer -> [Integer]
forall a. Enum a => a -> [a]
enumFrom Integer
a)
    enumFromThen :: Quarter -> Quarter -> [Quarter]
enumFromThen (MkQuarter Integer
a) (MkQuarter Integer
b) = (Integer -> Quarter) -> [Integer] -> [Quarter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (Integer -> Integer -> [Integer]
forall a. Enum a => a -> a -> [a]
enumFromThen Integer
a Integer
b)
    enumFromTo :: Quarter -> Quarter -> [Quarter]
enumFromTo (MkQuarter Integer
a) (MkQuarter Integer
b) = (Integer -> Quarter) -> [Integer] -> [Quarter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (Integer -> Integer -> [Integer]
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) =
        (Integer -> Quarter) -> [Integer] -> [Quarter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter (Integer -> Integer -> Integer -> [Integer]
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) = (Integer -> Quarter) -> [Integer] -> [Quarter]
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap Integer -> Quarter
MkQuarter ((Integer, Integer) -> [Integer]
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) = (Integer, Integer) -> Integer -> Int
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) = (Integer, Integer) -> Integer -> Bool
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) = (Integer, Integer) -> Int
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) = Integer -> String
forall t. ShowPadded t => t -> String
show4 Integer
y String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
"-" String -> ShowS
forall a. [a] -> [a] -> [a]
++ QuarterOfYear -> String
forall a. Show a => a -> String
show QuarterOfYear
qy

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

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

{-# COMPLETE YearQuarter #-}

monthOfYearQuarter :: MonthOfYear -> QuarterOfYear
monthOfYearQuarter :: Int -> QuarterOfYear
monthOfYearQuarter Int
my | Int
my Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
3 = QuarterOfYear
Q1
monthOfYearQuarter Int
my | Int
my Int -> Int -> Bool
forall a. Ord a => a -> a -> Bool
<= Int
6 = QuarterOfYear
Q2
monthOfYearQuarter Int
my | Int
my Int -> Int -> Bool
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 (QuarterOfYear -> Quarter) -> QuarterOfYear -> Quarter
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