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