chore(term): use time range formatter
This commit is contained in:
parent
446ab76286
commit
b069282d0a
@ -77,20 +77,18 @@ getTermShowR = do
|
||||
-> cell $ formatTime SelFormatDate termEnd >>= toWidget
|
||||
, sortable Nothing (i18nCell MsgTermHolidays) $ \(Entity _ Term{..},_, _)
|
||||
-> cell $ do
|
||||
let termHolidays' = groupHolidays termHolidays
|
||||
[whamlet|
|
||||
$newline never
|
||||
<ul .list--inline .list--comma-separated>
|
||||
$forall holiday <- termHolidays'
|
||||
$case holiday
|
||||
$of Left singleHoliday
|
||||
<li>^{formatTimeW SelFormatDate singleHoliday}
|
||||
$of Right (startD, endD)
|
||||
<li>
|
||||
^{formatTimeW SelFormatDate startD}
|
||||
–
|
||||
^{formatTimeW SelFormatDate endD}
|
||||
|]
|
||||
let termHolidays' = groupHolidays termHolidays
|
||||
[whamlet|
|
||||
$newline never
|
||||
<ul .list--inline .list--comma-separated>
|
||||
$forall holiday <- termHolidays'
|
||||
<li>
|
||||
$case holiday
|
||||
$of Left singleHoliday
|
||||
^{formatTimeW SelFormatDate singleHoliday}
|
||||
$of Right (startD, endD)
|
||||
^{formatTimeRangeW SelFormatDate startD (Just endD)}
|
||||
|]
|
||||
]
|
||||
dbtSorting = Map.fromList
|
||||
[ ( "start"
|
||||
|
||||
@ -333,21 +333,29 @@ formatTimeRange' :: ( HasLocalTime t, HasLocalTime t'
|
||||
-> t -- ^ Start
|
||||
-> Maybe t' -- ^ End
|
||||
-> m Text
|
||||
formatTimeRange' cont proj startT endT = do
|
||||
startT' <- cont proj startT
|
||||
formatTimeRange' cont proj startT Nothing = cont proj startT
|
||||
formatTimeRange' cont proj startT (Just endT) = do
|
||||
let
|
||||
locDayStart = localDay $ toLocalTime startT
|
||||
locDayEnd = localDay $ toLocalTime endT
|
||||
(yearStart, monthStart, dayStart) = toGregorian locDayStart
|
||||
(yearEnd , monthEnd , dayEnd ) = toGregorian locDayEnd
|
||||
endProj = (/\ proj) $ if
|
||||
| Just endT' <- endT
|
||||
, ((==) `on` localDay) (toLocalTime startT) (toLocalTime endT')
|
||||
-> SelFormatTime
|
||||
| locDayStart == locDayEnd
|
||||
-> SelFormatTime
|
||||
| otherwise
|
||||
-> SelFormatDateTime
|
||||
endT' <- for endT $ cont endProj
|
||||
|
||||
return $ case endT' of
|
||||
Nothing -> startT'
|
||||
Just endT'' -> [st|#{startT'} – #{endT''}|]
|
||||
|
||||
-> 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'}|]
|
||||
|
||||
formatTimeRange :: ( HasLocalTime t, HasLocalTime t'
|
||||
, MonadHandler m
|
||||
|
||||
Loading…
Reference in New Issue
Block a user