add intToText fn that doesn't use show

This commit is contained in:
Daniel Barlow 2024-11-10 22:47:35 +00:00
parent 1fd0435da6
commit e58b250024

View File

@ -11,6 +11,9 @@ import Control.Monad.Trans.Resource (runResourceT)
import Data.ByteString.Lazy as BS import Data.ByteString.Lazy as BS
import Data.List as List import Data.List as List
import Data.Text as T import Data.Text as T
import Data.Text.Lazy qualified as T (toStrict)
import Data.Text.Lazy.Builder qualified as B
import Data.Text.Lazy.Builder.Int qualified as B
import Data.Time.Clock (nominalDiffTimeToSeconds) import Data.Time.Clock (nominalDiffTimeToSeconds)
import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds) import Data.Time.Clock.POSIX (posixSecondsToUTCTime, utcTimeToPOSIXSeconds)
import Database.Persist.Postgresql (ConnectionPool, ConnectionString, SqlBackend, getPgInterval, runMigration, runSqlPool, withPostgresqlPool) import Database.Persist.Postgresql (ConnectionPool, ConnectionString, SqlBackend, getPgInterval, runMigration, runSqlPool, withPostgresqlPool)
@ -56,10 +59,13 @@ instance YesodPersist Souplesse where
Souplesse pool _ <- getYesod Souplesse pool _ <- getYesod
runSqlPool action pool runSqlPool action pool
intToText :: Integral a => a -> T.Text
intToText = T.toStrict . B.toLazyText . B.decimal
getCalendarR :: Handler Html getCalendarR :: Handler Html
getCalendarR = do getCalendarR = do
let fTime = T.pack . show . floor . utcTimeToPOSIXSeconds let fTime = intToText . floor . utcTimeToPOSIXSeconds
fDur = T.pack . show . ceiling . nominalDiffTimeToSeconds . getPgInterval fDur = intToText . ceiling . nominalDiffTimeToSeconds . getPgInterval
(formWidget, _) <- generateFormPost uploadForm (formWidget, _) <- generateFormPost uploadForm
sessions' <- runDB Session.recents sessions' <- runDB Session.recents
defaultLayout defaultLayout