{-# LANGUAGE TypeFamilies #-}

module Data.HodaTime.CalendarDateTime.Internal
(
   DayNth(..)
  ,Year
  ,WeekNumber
  ,DayOfMonth
  ,CalendarDate(..)
  ,NCalendarDate(..)
  ,CalendarDateTime(..)
  ,IsCalendar(..)
  ,HasDate(..)
  ,LocalTime(..)
  ,IsCalendarDateTime(..)
  ,at
)
where

import Data.HodaTime.Instant.Internal (Instant)
import Data.Int (Int32, Int8)
import Data.Word (Word8, Word32)

-- CalendarDate

-- | Used by several smart constructors to chose a day relative to the start or end of the month.
data DayNth =
    FourthToLast
  | ThirdToLast
  | SecondToLast
  | Last
  | First
  | Second
  | Third
  | Fourth
  | Fifth
  deriving (DayNth -> DayNth -> Bool
(DayNth -> DayNth -> Bool)
-> (DayNth -> DayNth -> Bool) -> Eq DayNth
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: DayNth -> DayNth -> Bool
== :: DayNth -> DayNth -> Bool
$c/= :: DayNth -> DayNth -> Bool
/= :: DayNth -> DayNth -> Bool
Eq, Int -> DayNth -> ShowS
[DayNth] -> ShowS
DayNth -> String
(Int -> DayNth -> ShowS)
-> (DayNth -> String) -> ([DayNth] -> ShowS) -> Show DayNth
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> DayNth -> ShowS
showsPrec :: Int -> DayNth -> ShowS
$cshow :: DayNth -> String
show :: DayNth -> String
$cshowList :: [DayNth] -> ShowS
showList :: [DayNth] -> ShowS
Show, Int -> DayNth
DayNth -> Int
DayNth -> [DayNth]
DayNth -> DayNth
DayNth -> DayNth -> [DayNth]
DayNth -> DayNth -> DayNth -> [DayNth]
(DayNth -> DayNth)
-> (DayNth -> DayNth)
-> (Int -> DayNth)
-> (DayNth -> Int)
-> (DayNth -> [DayNth])
-> (DayNth -> DayNth -> [DayNth])
-> (DayNth -> DayNth -> [DayNth])
-> (DayNth -> DayNth -> DayNth -> [DayNth])
-> Enum DayNth
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
$csucc :: DayNth -> DayNth
succ :: DayNth -> DayNth
$cpred :: DayNth -> DayNth
pred :: DayNth -> DayNth
$ctoEnum :: Int -> DayNth
toEnum :: Int -> DayNth
$cfromEnum :: DayNth -> Int
fromEnum :: DayNth -> Int
$cenumFrom :: DayNth -> [DayNth]
enumFrom :: DayNth -> [DayNth]
$cenumFromThen :: DayNth -> DayNth -> [DayNth]
enumFromThen :: DayNth -> DayNth -> [DayNth]
$cenumFromTo :: DayNth -> DayNth -> [DayNth]
enumFromTo :: DayNth -> DayNth -> [DayNth]
$cenumFromThenTo :: DayNth -> DayNth -> DayNth -> [DayNth]
enumFromThenTo :: DayNth -> DayNth -> DayNth -> [DayNth]
Enum)

type Year = Int
type DayOfMonth = Int
type WeekNumber = Int

data CalendarDate calendar = CalendarDate { forall calendar. CalendarDate calendar -> Int32
cdDays :: Int32, forall calendar. CalendarDate calendar -> Word8
cdDay :: Word8, forall calendar. CalendarDate calendar -> Word8
cdMonth :: Word8, forall calendar. CalendarDate calendar -> Word32
cdYear :: Word32 }
  deriving (CalendarDate calendar -> CalendarDate calendar -> Bool
(CalendarDate calendar -> CalendarDate calendar -> Bool)
-> (CalendarDate calendar -> CalendarDate calendar -> Bool)
-> Eq (CalendarDate calendar)
forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
== :: CalendarDate calendar -> CalendarDate calendar -> Bool
$c/= :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
/= :: CalendarDate calendar -> CalendarDate calendar -> Bool
Eq, Int -> CalendarDate calendar -> ShowS
[CalendarDate calendar] -> ShowS
CalendarDate calendar -> String
(Int -> CalendarDate calendar -> ShowS)
-> (CalendarDate calendar -> String)
-> ([CalendarDate calendar] -> ShowS)
-> Show (CalendarDate calendar)
forall calendar. Int -> CalendarDate calendar -> ShowS
forall calendar. [CalendarDate calendar] -> ShowS
forall calendar. CalendarDate calendar -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall calendar. Int -> CalendarDate calendar -> ShowS
showsPrec :: Int -> CalendarDate calendar -> ShowS
$cshow :: forall calendar. CalendarDate calendar -> String
show :: CalendarDate calendar -> String
$cshowList :: forall calendar. [CalendarDate calendar] -> ShowS
showList :: [CalendarDate calendar] -> ShowS
Show, Eq (CalendarDate calendar)
Eq (CalendarDate calendar) =>
(CalendarDate calendar -> CalendarDate calendar -> Ordering)
-> (CalendarDate calendar -> CalendarDate calendar -> Bool)
-> (CalendarDate calendar -> CalendarDate calendar -> Bool)
-> (CalendarDate calendar -> CalendarDate calendar -> Bool)
-> (CalendarDate calendar -> CalendarDate calendar -> Bool)
-> (CalendarDate calendar
    -> CalendarDate calendar -> CalendarDate calendar)
-> (CalendarDate calendar
    -> CalendarDate calendar -> CalendarDate calendar)
-> Ord (CalendarDate calendar)
CalendarDate calendar -> CalendarDate calendar -> Bool
CalendarDate calendar -> CalendarDate calendar -> Ordering
CalendarDate calendar
-> CalendarDate calendar -> CalendarDate calendar
forall calendar. Eq (CalendarDate calendar)
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
forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Ordering
forall calendar.
CalendarDate calendar
-> CalendarDate calendar -> CalendarDate calendar
$ccompare :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Ordering
compare :: CalendarDate calendar -> CalendarDate calendar -> Ordering
$c< :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
< :: CalendarDate calendar -> CalendarDate calendar -> Bool
$c<= :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
<= :: CalendarDate calendar -> CalendarDate calendar -> Bool
$c> :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
> :: CalendarDate calendar -> CalendarDate calendar -> Bool
$c>= :: forall calendar.
CalendarDate calendar -> CalendarDate calendar -> Bool
>= :: CalendarDate calendar -> CalendarDate calendar -> Bool
$cmax :: forall calendar.
CalendarDate calendar
-> CalendarDate calendar -> CalendarDate calendar
max :: CalendarDate calendar
-> CalendarDate calendar -> CalendarDate calendar
$cmin :: forall calendar.
CalendarDate calendar
-> CalendarDate calendar -> CalendarDate calendar
min :: CalendarDate calendar
-> CalendarDate calendar -> CalendarDate calendar
Ord)  -- TODO: Get rid of Show and define the other instances to only use cdDays

-- | Represents a specific date within its calendar system, with no reference to any time zone or time of day.
data NCalendarDate calendar = NCalendarDate { forall calendar. NCalendarDate calendar -> Int8
ncdCycle :: Int8, forall calendar. NCalendarDate calendar -> Word8
ncdCentury :: Word8, forall calendar. NCalendarDate calendar -> Word32
ncdDays :: Word32 }
  deriving (NCalendarDate calendar -> NCalendarDate calendar -> Bool
(NCalendarDate calendar -> NCalendarDate calendar -> Bool)
-> (NCalendarDate calendar -> NCalendarDate calendar -> Bool)
-> Eq (NCalendarDate calendar)
forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
== :: NCalendarDate calendar -> NCalendarDate calendar -> Bool
$c/= :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
/= :: NCalendarDate calendar -> NCalendarDate calendar -> Bool
Eq, Int -> NCalendarDate calendar -> ShowS
[NCalendarDate calendar] -> ShowS
NCalendarDate calendar -> String
(Int -> NCalendarDate calendar -> ShowS)
-> (NCalendarDate calendar -> String)
-> ([NCalendarDate calendar] -> ShowS)
-> Show (NCalendarDate calendar)
forall calendar. Int -> NCalendarDate calendar -> ShowS
forall calendar. [NCalendarDate calendar] -> ShowS
forall calendar. NCalendarDate calendar -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall calendar. Int -> NCalendarDate calendar -> ShowS
showsPrec :: Int -> NCalendarDate calendar -> ShowS
$cshow :: forall calendar. NCalendarDate calendar -> String
show :: NCalendarDate calendar -> String
$cshowList :: forall calendar. [NCalendarDate calendar] -> ShowS
showList :: [NCalendarDate calendar] -> ShowS
Show, Eq (NCalendarDate calendar)
Eq (NCalendarDate calendar) =>
(NCalendarDate calendar -> NCalendarDate calendar -> Ordering)
-> (NCalendarDate calendar -> NCalendarDate calendar -> Bool)
-> (NCalendarDate calendar -> NCalendarDate calendar -> Bool)
-> (NCalendarDate calendar -> NCalendarDate calendar -> Bool)
-> (NCalendarDate calendar -> NCalendarDate calendar -> Bool)
-> (NCalendarDate calendar
    -> NCalendarDate calendar -> NCalendarDate calendar)
-> (NCalendarDate calendar
    -> NCalendarDate calendar -> NCalendarDate calendar)
-> Ord (NCalendarDate calendar)
NCalendarDate calendar -> NCalendarDate calendar -> Bool
NCalendarDate calendar -> NCalendarDate calendar -> Ordering
NCalendarDate calendar
-> NCalendarDate calendar -> NCalendarDate calendar
forall calendar. Eq (NCalendarDate calendar)
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
forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Ordering
forall calendar.
NCalendarDate calendar
-> NCalendarDate calendar -> NCalendarDate calendar
$ccompare :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Ordering
compare :: NCalendarDate calendar -> NCalendarDate calendar -> Ordering
$c< :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
< :: NCalendarDate calendar -> NCalendarDate calendar -> Bool
$c<= :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
<= :: NCalendarDate calendar -> NCalendarDate calendar -> Bool
$c> :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
> :: NCalendarDate calendar -> NCalendarDate calendar -> Bool
$c>= :: forall calendar.
NCalendarDate calendar -> NCalendarDate calendar -> Bool
>= :: NCalendarDate calendar -> NCalendarDate calendar -> Bool
$cmax :: forall calendar.
NCalendarDate calendar
-> NCalendarDate calendar -> NCalendarDate calendar
max :: NCalendarDate calendar
-> NCalendarDate calendar -> NCalendarDate calendar
$cmin :: forall calendar.
NCalendarDate calendar
-> NCalendarDate calendar -> NCalendarDate calendar
min :: NCalendarDate calendar
-> NCalendarDate calendar -> NCalendarDate calendar
Ord)  -- TODO: Get rid of Show and define the other instances to only use cdDays

-- NOTE: This is a test form of the calendar date that only stores the cycle.  Everything else will be pulled from the date cache table, as required
--data CalendarDate o calendar = CalendarDate { cdDays :: Int32, cdCycle :: Word8, ldOptions :: o }
--  deriving (Eq, Show, Ord)

class IsCalendar cal where
  type Date cal
  data DayOfWeek cal
  data Month cal
  day' :: Functor f => (DayOfMonth -> f DayOfMonth) -> CalendarDate cal -> f (CalendarDate cal)
  month' :: CalendarDate cal -> Month cal
  monthl' :: Functor f => (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
  year' :: Functor f => (Year -> f Year) -> CalendarDate cal -> f (CalendarDate cal)
  dayOfWeek' :: CalendarDate cal -> DayOfWeek cal
  next' :: Int -> DayOfWeek cal -> CalendarDate cal -> CalendarDate cal
  previous' :: Int -> DayOfWeek cal -> CalendarDate cal -> CalendarDate cal

class HasDate d where
  type DoW d
  type MoY d
  -- | Lens for the day component of a 'HasDate'.  Please note that days are not clamped: if you add e.g. 400 days then the month and year will roll
  day :: Functor f => (DayOfMonth -> f DayOfMonth) -> d -> f d
  -- | Accessor for the Month component of a 'HasDate'.
  month :: d -> MoY d
  -- | Lens for interacting with the month component of a 'HasDate'.  Please note that we convert the month to an Int so meaningful math can be done on it.  Also
  --   please note that the day will be unaffected except in the case of "end of month" days which may clamp.  Note that this clamping will only occur as a final step,
  --   so that
  --
  --   >>> modify monthl (+ 2) <$> Gregorian.calendarDate 31 January 2000
  --   Just (CalendarDate 31 March 2000)
  --
  --   and not 29th of March as would happen with some libraries.
  monthl :: Functor f => (Int -> f Int) -> d -> f d
  -- | Lens for the year component of a 'HasDate'.  Please note that the rest of the date is left as is, with two exceptions: Feb 29 will clamp to 28 in a non-leapyear
  --   and if the new year is earlier than the earliest supported year it will clamp back to that year
  year :: Functor f => (Year -> f Year) -> d -> f d
  -- | Accessor for the Day of the week enum of a 'HasDate', for example:
  --
  -- >>> dayOfWeek . fromJust $ Gregorian.calendarDate 31 January 2000
  -- Monday
  dayOfWeek :: d -> DoW d
  -- | Returns a 'HasDate' shifted to the nth next Day of Week from the current 'HasDate', for example:
  --
  -- >>> next 1 Monday . fromJust $ Gregorian.calendarDate 31 January 2000
  -- CalendarDate 7 February 2000
  next :: Int -> DoW d -> d -> d
  -- | Returns a 'HasDate' shifted to the nth previous Day of Week from the current 'HasDate', for example:
  --
  -- >>> previous 1 Monday . fromJust $ Gregorian.calendarDate 31 January 2000
  -- CalendarDate 24 January 2000
  previous :: Int -> DoW d -> d -> d

instance (IsCalendar cal) => HasDate (CalendarDate cal) where
  type DoW (CalendarDate cal) = DayOfWeek cal
  type MoY (CalendarDate cal) = Month cal
  day :: forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
day = (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall cal (f :: * -> *).
(IsCalendar cal, Functor f) =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
day'
  month :: CalendarDate cal -> MoY (CalendarDate cal)
month = CalendarDate cal -> MoY (CalendarDate cal)
CalendarDate cal -> Month cal
forall cal. IsCalendar cal => CalendarDate cal -> Month cal
month'
  monthl :: forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
monthl = (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall cal (f :: * -> *).
(IsCalendar cal, Functor f) =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
monthl'
  year :: forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
year = (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall cal (f :: * -> *).
(IsCalendar cal, Functor f) =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
year'
  dayOfWeek :: CalendarDate cal -> DoW (CalendarDate cal)
dayOfWeek = CalendarDate cal -> DoW (CalendarDate cal)
CalendarDate cal -> DayOfWeek cal
forall cal. IsCalendar cal => CalendarDate cal -> DayOfWeek cal
dayOfWeek'
  next :: Int
-> DoW (CalendarDate cal) -> CalendarDate cal -> CalendarDate cal
next = Int
-> DoW (CalendarDate cal) -> CalendarDate cal -> CalendarDate cal
Int -> DayOfWeek cal -> CalendarDate cal -> CalendarDate cal
forall cal.
IsCalendar cal =>
Int -> DayOfWeek cal -> CalendarDate cal -> CalendarDate cal
next'
  previous :: Int
-> DoW (CalendarDate cal) -> CalendarDate cal -> CalendarDate cal
previous = Int
-> DoW (CalendarDate cal) -> CalendarDate cal -> CalendarDate cal
Int -> DayOfWeek cal -> CalendarDate cal -> CalendarDate cal
forall cal.
IsCalendar cal =>
Int -> DayOfWeek cal -> CalendarDate cal -> CalendarDate cal
previous'

-- LocalTime

-- | Represents a specific time of day with no reference to any calendar, date or time zone.
data LocalTime = LocalTime { LocalTime -> Word32
ltSecs :: Word32, LocalTime -> Word32
ltNsecs :: Word32 }
  deriving (LocalTime -> LocalTime -> Bool
(LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool) -> Eq LocalTime
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: LocalTime -> LocalTime -> Bool
== :: LocalTime -> LocalTime -> Bool
$c/= :: LocalTime -> LocalTime -> Bool
/= :: LocalTime -> LocalTime -> Bool
Eq, Eq LocalTime
Eq LocalTime =>
(LocalTime -> LocalTime -> Ordering)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> Bool)
-> (LocalTime -> LocalTime -> LocalTime)
-> (LocalTime -> LocalTime -> LocalTime)
-> Ord LocalTime
LocalTime -> LocalTime -> Bool
LocalTime -> LocalTime -> Ordering
LocalTime -> LocalTime -> LocalTime
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 :: LocalTime -> LocalTime -> Ordering
compare :: LocalTime -> LocalTime -> Ordering
$c< :: LocalTime -> LocalTime -> Bool
< :: LocalTime -> LocalTime -> Bool
$c<= :: LocalTime -> LocalTime -> Bool
<= :: LocalTime -> LocalTime -> Bool
$c> :: LocalTime -> LocalTime -> Bool
> :: LocalTime -> LocalTime -> Bool
$c>= :: LocalTime -> LocalTime -> Bool
>= :: LocalTime -> LocalTime -> Bool
$cmax :: LocalTime -> LocalTime -> LocalTime
max :: LocalTime -> LocalTime -> LocalTime
$cmin :: LocalTime -> LocalTime -> LocalTime
min :: LocalTime -> LocalTime -> LocalTime
Ord, Int -> LocalTime -> ShowS
[LocalTime] -> ShowS
LocalTime -> String
(Int -> LocalTime -> ShowS)
-> (LocalTime -> String)
-> ([LocalTime] -> ShowS)
-> Show LocalTime
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> LocalTime -> ShowS
showsPrec :: Int -> LocalTime -> ShowS
$cshow :: LocalTime -> String
show :: LocalTime -> String
$cshowList :: [LocalTime] -> ShowS
showList :: [LocalTime] -> ShowS
Show)    -- TODO: Remove Show

-- CalendarDateTime

-- | Represents a specific date and time within its calendar system.  NOTE: a CalendarDateTime does
--   *not* represent a specific time on the global time line because e.g. "10.March.2006 4pm" is a different instant
--   in most time zones.  Convert it to a ZonedDateTime first if you wish to convert to an instant (or use a convenience
--   function).
data CalendarDateTime calendar = CalendarDateTime (CalendarDate calendar) LocalTime
  deriving (CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
(CalendarDateTime calendar -> CalendarDateTime calendar -> Bool)
-> (CalendarDateTime calendar -> CalendarDateTime calendar -> Bool)
-> Eq (CalendarDateTime calendar)
forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
== :: CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
$c/= :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
/= :: CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
Eq, Int -> CalendarDateTime calendar -> ShowS
[CalendarDateTime calendar] -> ShowS
CalendarDateTime calendar -> String
(Int -> CalendarDateTime calendar -> ShowS)
-> (CalendarDateTime calendar -> String)
-> ([CalendarDateTime calendar] -> ShowS)
-> Show (CalendarDateTime calendar)
forall calendar. Int -> CalendarDateTime calendar -> ShowS
forall calendar. [CalendarDateTime calendar] -> ShowS
forall calendar. CalendarDateTime calendar -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall calendar. Int -> CalendarDateTime calendar -> ShowS
showsPrec :: Int -> CalendarDateTime calendar -> ShowS
$cshow :: forall calendar. CalendarDateTime calendar -> String
show :: CalendarDateTime calendar -> String
$cshowList :: forall calendar. [CalendarDateTime calendar] -> ShowS
showList :: [CalendarDateTime calendar] -> ShowS
Show, Eq (CalendarDateTime calendar)
Eq (CalendarDateTime calendar) =>
(CalendarDateTime calendar
 -> CalendarDateTime calendar -> Ordering)
-> (CalendarDateTime calendar -> CalendarDateTime calendar -> Bool)
-> (CalendarDateTime calendar -> CalendarDateTime calendar -> Bool)
-> (CalendarDateTime calendar -> CalendarDateTime calendar -> Bool)
-> (CalendarDateTime calendar -> CalendarDateTime calendar -> Bool)
-> (CalendarDateTime calendar
    -> CalendarDateTime calendar -> CalendarDateTime calendar)
-> (CalendarDateTime calendar
    -> CalendarDateTime calendar -> CalendarDateTime calendar)
-> Ord (CalendarDateTime calendar)
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
CalendarDateTime calendar -> CalendarDateTime calendar -> Ordering
CalendarDateTime calendar
-> CalendarDateTime calendar -> CalendarDateTime calendar
forall calendar. Eq (CalendarDateTime calendar)
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
forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Ordering
forall calendar.
CalendarDateTime calendar
-> CalendarDateTime calendar -> CalendarDateTime calendar
$ccompare :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Ordering
compare :: CalendarDateTime calendar -> CalendarDateTime calendar -> Ordering
$c< :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
< :: CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
$c<= :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
<= :: CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
$c> :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
> :: CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
$c>= :: forall calendar.
CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
>= :: CalendarDateTime calendar -> CalendarDateTime calendar -> Bool
$cmax :: forall calendar.
CalendarDateTime calendar
-> CalendarDateTime calendar -> CalendarDateTime calendar
max :: CalendarDateTime calendar
-> CalendarDateTime calendar -> CalendarDateTime calendar
$cmin :: forall calendar.
CalendarDateTime calendar
-> CalendarDateTime calendar -> CalendarDateTime calendar
min :: CalendarDateTime calendar
-> CalendarDateTime calendar -> CalendarDateTime calendar
Ord)

instance (IsCalendar cal) => HasDate (CalendarDateTime cal) where
  type DoW (CalendarDateTime cal) = DayOfWeek cal
  type MoY (CalendarDateTime cal) = Month cal
  day :: forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDateTime cal -> f (CalendarDateTime cal)
day Int -> f Int
f (CalendarDateTime CalendarDate cal
cd LocalTime
lt) = (CalendarDate cal -> LocalTime -> CalendarDateTime cal)
-> LocalTime -> CalendarDate cal -> CalendarDateTime cal
forall a b c. (a -> b -> c) -> b -> a -> c
flip CalendarDate cal -> LocalTime -> CalendarDateTime cal
forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
CalendarDateTime LocalTime
lt (CalendarDate cal -> CalendarDateTime cal)
-> f (CalendarDate cal) -> f (CalendarDateTime cal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall d (f :: * -> *).
(HasDate d, Functor f) =>
(Int -> f Int) -> d -> f d
forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
day Int -> f Int
f CalendarDate cal
cd
  month :: CalendarDateTime cal -> MoY (CalendarDateTime cal)
month (CalendarDateTime CalendarDate cal
cd LocalTime
_) = CalendarDate cal -> MoY (CalendarDate cal)
forall d. HasDate d => d -> MoY d
month CalendarDate cal
cd
  monthl :: forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDateTime cal -> f (CalendarDateTime cal)
monthl Int -> f Int
f (CalendarDateTime CalendarDate cal
cd LocalTime
lt) = (CalendarDate cal -> LocalTime -> CalendarDateTime cal)
-> LocalTime -> CalendarDate cal -> CalendarDateTime cal
forall a b c. (a -> b -> c) -> b -> a -> c
flip CalendarDate cal -> LocalTime -> CalendarDateTime cal
forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
CalendarDateTime LocalTime
lt (CalendarDate cal -> CalendarDateTime cal)
-> f (CalendarDate cal) -> f (CalendarDateTime cal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall d (f :: * -> *).
(HasDate d, Functor f) =>
(Int -> f Int) -> d -> f d
forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
monthl Int -> f Int
f CalendarDate cal
cd
  year :: forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDateTime cal -> f (CalendarDateTime cal)
year Int -> f Int
f (CalendarDateTime CalendarDate cal
cd LocalTime
lt) = (CalendarDate cal -> LocalTime -> CalendarDateTime cal)
-> LocalTime -> CalendarDate cal -> CalendarDateTime cal
forall a b c. (a -> b -> c) -> b -> a -> c
flip CalendarDate cal -> LocalTime -> CalendarDateTime cal
forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
CalendarDateTime LocalTime
lt (CalendarDate cal -> CalendarDateTime cal)
-> f (CalendarDate cal) -> f (CalendarDateTime cal)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
forall d (f :: * -> *).
(HasDate d, Functor f) =>
(Int -> f Int) -> d -> f d
forall (f :: * -> *).
Functor f =>
(Int -> f Int) -> CalendarDate cal -> f (CalendarDate cal)
year Int -> f Int
f CalendarDate cal
cd
  dayOfWeek :: CalendarDateTime cal -> DoW (CalendarDateTime cal)
dayOfWeek (CalendarDateTime CalendarDate cal
cd LocalTime
_) = CalendarDate cal -> DoW (CalendarDate cal)
forall d. HasDate d => d -> DoW d
dayOfWeek CalendarDate cal
cd
  next :: Int
-> DoW (CalendarDateTime cal)
-> CalendarDateTime cal
-> CalendarDateTime cal
next Int
i DoW (CalendarDateTime cal)
dow (CalendarDateTime CalendarDate cal
cd LocalTime
lt) = CalendarDate cal -> LocalTime -> CalendarDateTime cal
forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
CalendarDateTime (Int
-> DoW (CalendarDate cal) -> CalendarDate cal -> CalendarDate cal
forall d. HasDate d => Int -> DoW d -> d -> d
next Int
i DoW (CalendarDateTime cal)
DoW (CalendarDate cal)
dow CalendarDate cal
cd) LocalTime
lt
  previous :: Int
-> DoW (CalendarDateTime cal)
-> CalendarDateTime cal
-> CalendarDateTime cal
previous Int
i DoW (CalendarDateTime cal)
dow (CalendarDateTime CalendarDate cal
cd LocalTime
lt) = CalendarDate cal -> LocalTime -> CalendarDateTime cal
forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
CalendarDateTime (Int
-> DoW (CalendarDate cal) -> CalendarDate cal -> CalendarDate cal
forall d. HasDate d => Int -> DoW d -> d -> d
previous Int
i DoW (CalendarDateTime cal)
DoW (CalendarDate cal)
dow CalendarDate cal
cd) LocalTime
lt

-- | Private class used to allow conversions to and from CalendarDateTime for a given calendar.  If you see this in the documentation, consider it a bug
class IsCalendarDateTime cal where
  -- | Convert an Instant which has already been converted to the correct time for the Calendar and TimeZone into CalendarDateTime
  fromAdjustedInstant :: Instant -> CalendarDateTime cal
  -- | Convert a CalendarDateTime directly to an Instant.  Needed because different calendars use different epochs.  If this ever changes we can revisit this
  toUnadjustedInstant :: CalendarDateTime cal -> Instant

-- constructors

-- | Returns a 'CalendarDateTime' of the 'CalendarDate' at the given 'LocalTime'
at :: CalendarDate cal -> LocalTime -> CalendarDateTime cal
at :: forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
at = CalendarDate cal -> LocalTime -> CalendarDateTime cal
forall calendar.
CalendarDate calendar -> LocalTime -> CalendarDateTime calendar
CalendarDateTime