{-# LANGUAGE CPP #-}
#if __GLASGOW_HASKELL__ >= 710
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
#endif
module Data.Time.Calendar.OrdinalDate.Compat (
Day, Year, DayOfYear, WeekOfYear,
toOrdinalDate,
fromOrdinalDate,
#if __GLASGOW_HASKELL__ >= 710
pattern YearDay,
#endif
fromOrdinalDateValid,
showOrdinalDate,
isLeapYear,
mondayStartWeek,
sundayStartWeek,
fromMondayStartWeek,
fromMondayStartWeekValid,
fromSundayStartWeek,
fromSundayStartWeekValid,
) where
import Data.Time.Orphans ()
import Data.Time.Calendar.OrdinalDate hiding (fromSundayStartWeekValid)
#if MIN_VERSION_time(1,6,0)
import Data.Time.Calendar.OrdinalDate (fromSundayStartWeekValid)
#else
import Data.Time.Calendar.Private
#endif
#if !MIN_VERSION_time(1,11,0)
import Data.Time.Calendar
import Data.Time.Calendar.Types
#endif
#if !MIN_VERSION_time(1,11,0)
#if __GLASGOW_HASKELL__ >= 710
pattern YearDay :: Year -> DayOfYear -> Day
pattern $bYearDay :: Year -> DayOfYear -> Day
$mYearDay :: forall r. Day -> (Year -> DayOfYear -> r) -> (Void# -> r) -> r
YearDay y d <- (toOrdinalDate -> (y,d)) where
YearDay Year
y DayOfYear
d = Year -> DayOfYear -> Day
fromOrdinalDate Year
y DayOfYear
d
#if __GLASGOW_HASKELL__ >= 802
{-# COMPLETE YearDay #-}
#endif
#endif
#endif
#if !MIN_VERSION_time(1,6,0)
fromSundayStartWeekValid ::
Year
-> WeekOfYear
-> Int
-> Maybe Day
fromSundayStartWeekValid year w d = do
d' <- clipValid 0 6 d
let
firstDay = fromOrdinalDate year 1
zbFirstSunday = (4 - toModifiedJulianDay firstDay) `mod` 7
zbWeek = w - 1
zbDay = d'
zbYearDay = zbFirstSunday + 7 * toInteger zbWeek + toInteger zbDay
zbYearDay' <-
clipValid
0
(if isLeapYear year
then 365
else 364)
zbYearDay
return $ addDays zbYearDay' firstDay
#endif