{-# OPTIONS -fno-warn-orphans #-}-- #hidemoduleData.Time.Calendar.Gregorian(-- * Gregorian calendartoGregorian,fromGregorian,fromGregorianValid,showGregorian,gregorianMonthLength,-- calendrical arithmetic-- e.g. "one month after March 31st"addGregorianMonthsClip,addGregorianMonthsRollOver,addGregorianYearsClip,addGregorianYearsRollOver,-- re-exported from OrdinalDateisLeapYear)whereimportData.Time.Calendar.MonthDayimportData.Time.Calendar.OrdinalDateimportData.Time.Calendar.DaysimportData.Time.Calendar.Private-- | convert to proleptic Gregorian calendar. First element of result is year, second month number (1-12), third day (1-31).toGregorian::Day->(Integer,Int,Int)toGregoriandate=(year,month,day)where(year,yd)=toOrdinalDatedate(month,day)=dayOfYearToMonthAndDay(isLeapYearyear)yd-- | convert from proleptic Gregorian calendar. First argument is year, second month number (1-12), third day (1-31).-- Invalid values will be clipped to the correct range, month first, then day.fromGregorian::Integer->Int->Int->DayfromGregorianyearmonthday=fromOrdinalDateyear(monthAndDayToDayOfYear(isLeapYearyear)monthday)-- | convert from proleptic Gregorian calendar. First argument is year, second month number (1-12), third day (1-31).-- Invalid values will return NothingfromGregorianValid::Integer->Int->Int->MaybeDayfromGregorianValidyearmonthday=dodoy<-monthAndDayToDayOfYearValid(isLeapYearyear)monthdayfromOrdinalDateValidyeardoy-- | show in ISO 8601 format (yyyy-mm-dd)showGregorian::Day->StringshowGregoriandate=(show4(Just'0')y)++"-"++(show2(Just'0')m)++"-"++(show2(Just'0')d)where(y,m,d)=toGregoriandate-- | The number of days in a given month according to the proleptic Gregorian calendar. First argument is year, second is month.gregorianMonthLength::Integer->Int->IntgregorianMonthLengthyear=monthLength(isLeapYearyear)rolloverMonths::(Integer,Integer)->(Integer,Int)rolloverMonths(y,m)=(y+(div(m-1)12),fromIntegral(mod(m-1)12)+1)addGregorianMonths::Integer->Day->(Integer,Int,Int)addGregorianMonthsnday=(y',m',d)where(y,m,d)=toGregorianday(y',m')=rolloverMonths(y,fromIntegralm+n)-- | Add months, with days past the last day of the month clipped to the last day.-- For instance, 2005-01-30 + 1 month = 2005-02-28.addGregorianMonthsClip::Integer->Day->DayaddGregorianMonthsClipnday=fromGregorianymdwhere(y,m,d)=addGregorianMonthsnday-- | Add months, with days past the last day of the month rolling over to the next month.-- For instance, 2005-01-30 + 1 month = 2005-03-02.addGregorianMonthsRollOver::Integer->Day->DayaddGregorianMonthsRollOvernday=addDays(fromIntegrald-1)(fromGregorianym1)where(y,m,d)=addGregorianMonthsnday-- | Add years, matching month and day, with Feb 29th clipped to Feb 28th if necessary.-- For instance, 2004-02-29 + 2 years = 2006-02-28.addGregorianYearsClip::Integer->Day->DayaddGregorianYearsClipn=addGregorianMonthsClip(n*12)-- | Add years, matching month and day, with Feb 29th rolled over to Mar 1st if necessary.-- For instance, 2004-02-29 + 2 years = 2006-03-01.addGregorianYearsRollOver::Integer->Day->DayaddGregorianYearsRollOvern=addGregorianMonthsRollOver(n*12)-- orphan instanceinstanceShowDaywhereshow=showGregorian