diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-16 00:32:55 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-16 00:32:55 -0400 |
commit | 24dbb9fbd618a2ba29b48d8bf76c0d5a9a5b3ce3 (patch) | |
tree | 4a51cc33aa295ac95ffb03cbe586d7eedebc9ece | |
parent | 789bf4d934666918401bf599e7b7faf430bd43ac (diff) |
tweak numerical output; fix warnings
-rwxr-xr-x | countdown.hs | 12 |
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 | ||
133 | printRemain unit quantity = printf "%d %s%s remain%s" | ||
134 | |||
135 | showTime :: NominalDiffTime -> String | 133 | showTime :: NominalDiffTime -> String |
136 | showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) | 134 | showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) |
137 | showTime t | t == 1 = "1 second" | 135 | showTime 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 | ||
257 | commasF :: RealFrac x => Int -> x -> Text | 255 | commasF' 1 n = if (floor (n * 10) `mod` 10 :: Int) == 0 then commasF 0 n else commasF 1 n |
256 | commasF' p n = commasF p n | ||
257 | |||
258 | commasF', commasF :: RealFrac x => Int -> x -> Text | ||
258 | commasF precision = prettyF cfg | 259 | commasF 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 | |||
275 | diffZonedTime :: ZonedTime -> ZonedTime -> NominalDiffTime | 276 | diffZonedTime :: ZonedTime -> ZonedTime -> NominalDiffTime |
276 | diffZonedTime = diffLocalTime `Prelude.on` zonedTimeToLocalTime | 277 | diffZonedTime = diffLocalTime `Prelude.on` zonedTimeToLocalTime |
277 | 278 | ||
279 | isNewYearsEve :: LocalTime -> Bool | ||
278 | isNewYearsEve t = dayNumOfYear t == daysInYear t | 280 | isNewYearsEve t = dayNumOfYear t == daysInYear t |
279 | 281 | ||
280 | queueNextEvent :: MonadIO m => Bool -> BChan CustomEvent -> m ZonedTime | 282 | queueNextEvent :: MonadIO m => Bool -> BChan CustomEvent -> m ZonedTime |