Get rid of hours display in date diffs (fixes #217)

Pinging @chrisdone and @juhp
This commit is contained in:
Michael Snoyman 2016-12-12 11:44:29 +02:00
parent bcf86a1d40
commit e5a7e9b2e8
3 changed files with 13 additions and 12 deletions

View File

@ -8,8 +8,6 @@ module Handler.Home
) where
import Data.Time.Clock
import Formatting
import Formatting.Time
import Import
import Stackage.Database
import Yesod.GitRepo (grContent)
@ -38,10 +36,7 @@ getHomeR = track "Handler.Snapshots.getAllSnapshotsR" $ do
where uncrapify now' snapshot =
( snapshotName snapshot
, snapshotTitle snapshot
, format (diff True)
$ diffUTCTime
(UTCTime (snapshotCreated snapshot) 0)
now'
, dateDiff now' (snapshotCreated snapshot)
)
groupUp now' = groupBy (on (==) (\(_,_,uploaded) -> uploaded))
. map (uncrapify now')

View File

@ -3,8 +3,6 @@
module Handler.Snapshots where
import Data.Time.Clock
import Formatting
import Formatting.Time
import Import
import Stackage.Database
@ -40,10 +38,7 @@ getAllSnapshotsR = track "Handler.Snapshots.getAllSnapshotsR" $ do
where uncrapify now' snapshot =
( snapshotName snapshot
, snapshotTitle snapshot
, format (diff True)
$ diffUTCTime
(UTCTime (snapshotCreated snapshot) 0)
now'
, dateDiff now' (snapshotCreated snapshot)
)
groupUp now' = groupBy (on (==) (\(_,_,uploaded) -> uploaded))
. map (uncrapify now')

View File

@ -13,6 +13,8 @@ import Data.Text.Read (decimal)
import Data.Time.Clock (diffUTCTime)
import qualified Prometheus as P
import Stackage.Database (SnapName)
import Formatting (format)
import Formatting.Time (diff)
parseLtsPair :: Text -> Maybe (Int, Int)
parseLtsPair t1 = do
@ -60,3 +62,12 @@ track name inner = do
"stackage_server_fn"
"Stackage Server function call (duration in microseconds).")
P.defaultQuantiles))
dateDiff :: UTCTime -- ^ now
-> Day -- ^ target
-> LText
dateDiff (UTCTime now' _) target
| now' == target = "today"
| otherwise = format (diff True) $ diffUTCTime
(UTCTime target 0)
(UTCTime now' 0)