{-# LANGUAGE Safe #-}

-- | Year quarters.
module Data.Time.Calendar.Quarter (
    QuarterOfYear (..),
    addQuarters,
    diffQuarters,
    Quarter (..),
    pattern YearQuarter,
    monthOfYearQuarter,
    monthQuarter,
    dayQuarter,
    DayOfQuarter,
    pattern QuarterDay,
) 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 GHC.Generics
import qualified Language.Haskell.TH.Syntax as TH
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
$c== :: QuarterOfYear -> QuarterOfYear -> Bool
== :: QuarterOfYear -> QuarterOfYear -> Bool
$c/= :: QuarterOfYear -> QuarterOfYear -> Bool
/= :: 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
$ccompare :: QuarterOfYear -> QuarterOfYear -> Ordering
compare :: QuarterOfYear -> QuarterOfYear -> Ordering
$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
>= :: QuarterOfYear -> QuarterOfYear -> Bool
$cmax :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
max :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
$cmin :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
min :: QuarterOfYear -> QuarterOfYear -> QuarterOfYear
Ord, Typeable QuarterOfYear
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 -> Constr
QuarterOfYear -> DataType
(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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> QuarterOfYear -> c QuarterOfYear
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QuarterOfYear
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c QuarterOfYear
$ctoConstr :: QuarterOfYear -> Constr
toConstr :: QuarterOfYear -> Constr
$cdataTypeOf :: QuarterOfYear -> DataType
dataTypeOf :: QuarterOfYear -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QuarterOfYear)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c QuarterOfYear)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QuarterOfYear)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c QuarterOfYear)
$cgmapT :: (forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear
gmapT :: (forall b. Data b => b -> b) -> QuarterOfYear -> QuarterOfYear
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> QuarterOfYear -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> QuarterOfYear -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> QuarterOfYear -> u
$cgmapM :: forall (m :: * -> *).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m QuarterOfYear
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> QuarterOfYear -> m 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
$creadsPrec :: Int -> ReadS QuarterOfYear
readsPrec :: Int -> ReadS QuarterOfYear
$creadList :: ReadS [QuarterOfYear]
readList :: ReadS [QuarterOfYear]
$creadPrec :: ReadPrec QuarterOfYear
readPrec :: ReadPrec QuarterOfYear
$creadListPrec :: ReadPrec [QuarterOfYear]
readListPrec :: ReadPrec [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
$cshowsPrec :: Int -> QuarterOfYear -> ShowS
showsPrec :: Int -> QuarterOfYear -> ShowS
$cshow :: QuarterOfYear -> String
show :: QuarterOfYear -> String
$cshowList :: [QuarterOfYear] -> ShowS
showList :: [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
$crange :: (QuarterOfYear, QuarterOfYear) -> [QuarterOfYear]
range :: (QuarterOfYear, QuarterOfYear) -> [QuarterOfYear]
$cindex :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
index :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
$cunsafeIndex :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
unsafeIndex :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Int
$cinRange :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Bool
inRange :: (QuarterOfYear, QuarterOfYear) -> QuarterOfYear -> Bool
$crangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
rangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
$cunsafeRangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
unsafeRangeSize :: (QuarterOfYear, QuarterOfYear) -> Int
Ix, (forall (m :: * -> *). Quote m => QuarterOfYear -> m Exp)
-> (forall (m :: * -> *).
    Quote m =>
    QuarterOfYear -> Code m QuarterOfYear)
-> Lift QuarterOfYear
forall t.
(forall (m :: * -> *). Quote m => t -> m Exp)
-> (forall (m :: * -> *). Quote m => t -> Code m t) -> Lift t
forall (m :: * -> *). Quote m => QuarterOfYear -> m Exp
forall (m :: * -> *).
Quote m =>
QuarterOfYear -> Code m QuarterOfYear
$clift :: forall (m :: * -> *). Quote m => QuarterOfYear -> m Exp
lift :: forall (m :: * -> *). Quote m => QuarterOfYear -> m Exp
$cliftTyped :: forall (m :: * -> *).
Quote m =>
QuarterOfYear -> Code m QuarterOfYear
liftTyped :: forall (m :: * -> *).
Quote m =>
QuarterOfYear -> Code m QuarterOfYear
TH.Lift, (forall x. QuarterOfYear -> Rep QuarterOfYear x)
-> (forall x. Rep QuarterOfYear x -> QuarterOfYear)
-> Generic QuarterOfYear
forall x. Rep QuarterOfYear x -> QuarterOfYear
forall x. QuarterOfYear -> Rep QuarterOfYear x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. QuarterOfYear -> Rep QuarterOfYear x
from :: forall x. QuarterOfYear -> Rep QuarterOfYear x
$cto :: forall x. Rep QuarterOfYear x -> QuarterOfYear
to :: forall x. Rep QuarterOfYear x -> QuarterOfYear
Generic)

-- | 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
$c== :: Quarter -> Quarter -> Bool
== :: Quarter -> Quarter -> Bool
$c/= :: Quarter -> Quarter -> Bool
/= :: 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
$ccompare :: Quarter -> Quarter -> Ordering
compare :: Quarter -> Quarter -> Ordering
$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
>= :: Quarter -> Quarter -> Bool
$cmax :: Quarter -> Quarter -> Quarter
max :: Quarter -> Quarter -> Quarter
$cmin :: Quarter -> Quarter -> Quarter
min :: Quarter -> Quarter -> Quarter
Ord, Typeable Quarter
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 -> Constr
Quarter -> DataType
(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)
$cgfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quarter -> c Quarter
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> Quarter -> c Quarter
$cgunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Quarter
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c Quarter
$ctoConstr :: Quarter -> Constr
toConstr :: Quarter -> Constr
$cdataTypeOf :: Quarter -> DataType
dataTypeOf :: Quarter -> DataType
$cdataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Quarter)
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c Quarter)
$cdataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Quarter)
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Quarter)
$cgmapT :: (forall b. Data b => b -> b) -> Quarter -> Quarter
gmapT :: (forall b. Data b => b -> b) -> Quarter -> Quarter
$cgmapQl :: 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
$cgmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> Quarter -> r
$cgmapQ :: forall u. (forall d. Data d => d -> u) -> Quarter -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> Quarter -> [u]
$cgmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u
gmapQi :: forall u. Int -> (forall d. Data d => d -> u) -> Quarter -> u
$cgmapM :: forall (m :: * -> *).
Monad 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
$cgmapMp :: 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
$cgmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d) -> Quarter -> m Quarter
Data, Typeable, (forall x. Quarter -> Rep Quarter x)
-> (forall x. Rep Quarter x -> Quarter) -> Generic Quarter
forall x. Rep Quarter x -> Quarter
forall x. Quarter -> Rep Quarter x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cfrom :: forall x. Quarter -> Rep Quarter x
from :: forall x. Quarter -> Rep Quarter x
$cto :: forall x. Rep Quarter x -> Quarter
to :: forall x. Rep Quarter x -> Quarter
Generic)

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 a b. (a -> b) -> [a] -> [b]
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 a b. (a -> b) -> [a] -> [b]
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 a b. (a -> b) -> [a] -> [b]
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 a b. (a -> b) -> [a] -> [b]
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 a b. (a -> b) -> [a] -> [b]
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 a. a -> ReadPrec a
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

instance DayPeriod Quarter where
    periodFirstDay :: Quarter -> Day
periodFirstDay (YearQuarter Integer
y QuarterOfYear
q) =
        case QuarterOfYear
q of
            QuarterOfYear
Q1 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodFirstDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
January
            QuarterOfYear
Q2 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodFirstDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
April
            QuarterOfYear
Q3 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodFirstDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
July
            QuarterOfYear
Q4 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodFirstDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
October
    periodLastDay :: Quarter -> Day
periodLastDay (YearQuarter Integer
y QuarterOfYear
q) =
        case QuarterOfYear
q of
            QuarterOfYear
Q1 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodLastDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
March
            QuarterOfYear
Q2 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodLastDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
June
            QuarterOfYear
Q3 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodLastDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
September
            QuarterOfYear
Q4 -> Month -> Day
forall p. DayPeriod p => p -> Day
periodLastDay (Month -> Day) -> Month -> Day
forall a b. (a -> b) -> a -> b
$ Integer -> Int -> Month
YearMonth Integer
y Int
December
    dayPeriod :: Day -> Quarter
dayPeriod (MonthDay Month
m Int
_) = Month -> Quarter
monthQuarter Month
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 $mYearQuarter :: forall {r}.
Quarter -> (Integer -> QuarterOfYear -> r) -> ((# #) -> r) -> r
$bYearQuarter :: Integer -> QuarterOfYear -> Quarter
YearQuarter y qy <-
    MkQuarter ((\Integer
q -> Integer -> Integer -> (Integer, Integer)
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 (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 #-}

-- | The 'QuarterOfYear' this 'MonthOfYear' is in.
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

-- | The 'Quarter' this 'Month' is in.
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

-- | The 'Quarter' this 'Day' is in.
dayQuarter :: Day -> Quarter
dayQuarter :: Day -> Quarter
dayQuarter = Day -> Quarter
forall p. DayPeriod p => Day -> p
dayPeriod

-- | Bidirectional abstract constructor.
-- Invalid days of quarter will be clipped to the correct range.
--
-- @since 1.12.1
pattern QuarterDay :: Quarter -> DayOfQuarter -> Day
pattern $mQuarterDay :: forall {r}. Day -> (Quarter -> Int -> r) -> ((# #) -> r) -> r
$bQuarterDay :: Quarter -> Int -> Day
QuarterDay q dq <-
    (periodFromDay -> (q, dq))
    where
        QuarterDay = Quarter -> Int -> Day
forall p. DayPeriod p => p -> Int -> Day
periodToDay

{-# COMPLETE QuarterDay #-}