-- | ISO 8601 Week Date formatmoduleData.Time.Calendar.WeekDatewhereimportData.Time.Calendar.OrdinalDateimportData.Time.Calendar.DaysimportData.Time.Calendar.Private-- | Convert to ISO 8601 Week Date format. First element of result is year, second week number (1-53), third day of week (1 for Monday to 7 for Sunday).-- Note that \"Week\" years are not quite the same as Gregorian years, as the first day of the year is always a Monday.-- The first week of a year is the first week to contain at least four days in the corresponding Gregorian year.toWeekDate::Day->(Integer,Int,Int)toWeekDatedate@(ModifiedJulianDaymjd)=(y1,fromInteger(w1+1),fromIntegerd_mod_7+1)where(d_div_7,d_mod_7)=d`divMod`7(y0,yd)=toOrdinalDatedated=mjd+2foo::Integer->Integerfooy=bar(toModifiedJulianDay(fromOrdinalDatey6))bark=d_div_7-k`div`7(y1,w1)=casebar(d-toIntegeryd+4)of-1->(y0-1,foo(y0-1))52->iffoo(y0+1)==0then(y0+1,0)else(y0,52)w0->(y0,w0)-- | Convert from ISO 8601 Week Date format. First argument is year, second week number (1-52 or 53), third day of week (1 for Monday to 7 for Sunday).-- Invalid week and day values will be clipped to the correct range.fromWeekDate::Integer->Int->Int->DayfromWeekDateywd=ModifiedJulianDay(k-(modk7)+(toInteger(((clip1(iflongYearthen53else52)w)*7)+(clip17d)))-10)wherek=toModifiedJulianDay(fromOrdinalDatey6)longYear=casetoWeekDate(fromOrdinalDatey365)of(_,53,_)->True_->False-- | Convert from ISO 8601 Week Date format. First argument is year, second week number (1-52 or 53), third day of week (1 for Monday to 7 for Sunday).-- Invalid week and day values will return Nothing.fromWeekDateValid::Integer->Int->Int->MaybeDayfromWeekDateValidywd=dod'<-clipValid17dletlongYear=casetoWeekDate(fromOrdinalDatey365)of(_,53,_)->True_->Falsew'<-clipValid1(iflongYearthen53else52)wletk=toModifiedJulianDay(fromOrdinalDatey6)return(ModifiedJulianDay(k-(modk7)+(toInteger((w'*7)+d'))-10))-- | Show in ISO 8601 Week Date format as yyyy-Www-d (e.g. \"2006-W46-3\").showWeekDate::Day->StringshowWeekDatedate=(show4y)++"-W"++(show2w)++"-"++(showd)where(y,w,d)=toWeekDatedate