summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-16 00:32:55 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-16 00:32:55 -0400
commit24dbb9fbd618a2ba29b48d8bf76c0d5a9a5b3ce3 (patch)
tree4a51cc33aa295ac95ffb03cbe586d7eedebc9ece
parent789bf4d934666918401bf599e7b7faf430bd43ac (diff)
tweak numerical output; fix warnings
-rwxr-xr-xcountdown.hs12
1 files changed, 7 insertions, 5 deletions
diff --git a/countdown.hs b/countdown.hs
index 7c510b5..afd9266 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -130,8 +130,6 @@ drawUI st = [a]
130 (countdownWidget (isSimulatedTime st) $ st ^. stDisplayTime) 130 (countdownWidget (isSimulatedTime st) $ st ^. stDisplayTime)
131 ] 131 ]
132 132
133printRemain unit quantity = printf "%d %s%s remain%s"
134
135showTime :: NominalDiffTime -> String 133showTime :: NominalDiffTime -> String
136showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) 134showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float)
137showTime t | t == 1 = "1 second" 135showTime t | t == 1 = "1 second"
@@ -197,7 +195,7 @@ countdownWidget isSimulated t =
197 (commasF 2 minutesLeft) 195 (commasF 2 minutesLeft)
198 (pluralize $ (floor minutesLeft :: Integer)) 196 (pluralize $ (floor minutesLeft :: Integer))
199 (pluralizeVerb $ (floor minutesLeft :: Integer)) 197 (pluralizeVerb $ (floor minutesLeft :: Integer))
200 (commasF 1 secondsLeft) 198 (commasF' 1 secondsLeft)
201 (pluralize secondsLeft) 199 (pluralize secondsLeft)
202 (pluralizeVerb secondsLeft))) 200 (pluralizeVerb secondsLeft)))
203 , (borderWithLabel (str "Cosmic Time") $ 201 , (borderWithLabel (str "Cosmic Time") $
@@ -227,7 +225,7 @@ countdownWidget isSimulated t =
227 (str $ printf "Day %d of %d\nSecond %s of %s" 225 (str $ printf "Day %d of %d\nSecond %s of %s"
228 dayNum 226 dayNum
229 numDays 227 numDays
230 (commas $ 1 + toSeconds yearElapsed) 228 (commas $ (1 + toSeconds yearElapsed :: Int))
231 (commas $ toSeconds yearLength)) 229 (commas $ toSeconds yearLength))
232 , 230 ,
233 str " " 231 str " "
@@ -254,7 +252,10 @@ countdownWidget isSimulated t =
254 x // y = fromRational $ toRational x / toRational y :: Double 252 x // y = fromRational $ toRational x / toRational y :: Double
255 progressLabel = printf "%.6F%%" (100 * (yearElapsed // yearLength)) 253 progressLabel = printf "%.6F%%" (100 * (yearElapsed // yearLength))
256 254
257commasF :: RealFrac x => Int -> x -> Text 255commasF' 1 n = if (floor (n * 10) `mod` 10 :: Int) == 0 then commasF 0 n else commasF 1 n
256commasF' p n = commasF p n
257
258commasF', commasF :: RealFrac x => Int -> x -> Text
258commasF precision = prettyF cfg 259commasF precision = prettyF cfg
259 where 260 where
260 cfg = PrettyCfg precision (Just ',') '.' 261 cfg = PrettyCfg precision (Just ',') '.'
@@ -275,6 +276,7 @@ nextWholeSecond (ZonedTime (LocalTime day (TimeOfDay h m s)) z) = (ZonedTime (Lo
275diffZonedTime :: ZonedTime -> ZonedTime -> NominalDiffTime 276diffZonedTime :: ZonedTime -> ZonedTime -> NominalDiffTime
276diffZonedTime = diffLocalTime `Prelude.on` zonedTimeToLocalTime 277diffZonedTime = diffLocalTime `Prelude.on` zonedTimeToLocalTime
277 278
279isNewYearsEve :: LocalTime -> Bool
278isNewYearsEve t = dayNumOfYear t == daysInYear t 280isNewYearsEve t = dayNumOfYear t == daysInYear t
279 281
280queueNextEvent :: MonadIO m => Bool -> BChan CustomEvent -> m ZonedTime 282queueNextEvent :: MonadIO m => Bool -> BChan CustomEvent -> m ZonedTime