From 84481048dff6a6327a803c1dcc05e3d67dd7aaf8 Mon Sep 17 00:00:00 2001 From: Steffen Jost Date: Thu, 9 Mar 2023 11:13:58 +0000 Subject: [PATCH] chore(date): revert time range formatter --- src/Handler/Utils/DateTime.hs | 33 +++++++++++++-------------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/Handler/Utils/DateTime.hs b/src/Handler/Utils/DateTime.hs index 5cf0030fa..a29ff5f6b 100644 --- a/src/Handler/Utils/DateTime.hs +++ b/src/Handler/Utils/DateTime.hs @@ -333,29 +333,22 @@ formatTimeRange' :: ( HasLocalTime t, HasLocalTime t' -> t -- ^ Start -> Maybe t' -- ^ End -> m Text -formatTimeRange' cont proj startT Nothing = cont proj startT -formatTimeRange' cont proj startT (Just endT) = do +-- In order to abbreviate common same month time ranges, e.g. 24--26.12.23 on must take into account all DateFormatString, as some have the day on the end or feature a weekday +formatTimeRange' cont proj startT endT = do + startT' <- cont proj startT let - locDayStart = localDay $ toLocalTime startT - locDayEnd = localDay $ toLocalTime endT - (yearStart, monthStart, dayStart) = toGregorian locDayStart - (yearEnd , monthEnd , dayEnd ) = toGregorian locDayEnd endProj = (/\ proj) $ if - | locDayStart == locDayEnd - -> SelFormatTime + | Just endT' <- endT + , ((==) `on` localDay) (toLocalTime startT) (toLocalTime endT') + -> SelFormatTime | otherwise - -> SelFormatDateTime - startT' <- cont proj startT - endT' <- cont endProj endT - return $ if - | SelFormatDate == endProj - , yearStart == yearEnd - , monthStart == monthEnd - -> if dayStart == dayEnd - then startT' - else [st|#{dayStart} - #{endT'}|] -- does not work all date/time format strings! - | otherwise - -> [st|#{startT'} - #{endT'}|] + -> SelFormatDateTime + endT' <- for endT $ cont endProj + + return $ case endT' of + Nothing -> startT' + Just endT'' -> [st|#{startT'} – #{endT''}|] + formatTimeRange :: ( HasLocalTime t, HasLocalTime t' , MonadHandler m