summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-15 22:58:30 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-15 23:03:09 -0400
commitfab434598d0958c9cdc339822017748cc5bd2461 (patch)
tree80b32636de3a1583e33da5e2cc8bab60a59938bd
parentc70ec8a408400291abc83a701539db946444a053 (diff)
large number formatting
-rwxr-xr-xcountdown.hs15
-rw-r--r--package.yaml1
2 files changed, 14 insertions, 2 deletions
diff --git a/countdown.hs b/countdown.hs
index 3f39a7d..b53a3a4 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -22,6 +22,7 @@ import Control.Monad.RWS
22import Data.Time.Calendar.OrdinalDate 22import Data.Time.Calendar.OrdinalDate
23import Data.Text.Format.Numbers 23import Data.Text.Format.Numbers
24 24
25import Data.Text (unpack)
25import Control.Lens 26import Control.Lens
26import Control.Monad (void, forever) 27import Control.Monad (void, forever)
27import Control.Concurrent (threadDelay, forkIO) 28import Control.Concurrent (threadDelay, forkIO)
@@ -172,6 +173,15 @@ cosmicConversion = borderWithLabel (str "Cosmic Conversion") $ renderTable $
172 [str "100 years" , showCosmicYears 100] 173 [str "100 years" , showCosmicYears 100]
173 ] 174 ]
174 175
176showLarge :: Double -> String
177showLarge n | n >= 10 * 1000 * 1000 * 1000 = printf "%.0f billion" (n / (1000 * 1000 * 1000))
178showLarge n | n >= 1000 * 1000 * 1000 = printf "%.1f billion" (n / (1000 * 1000 * 1000))
179showLarge n | n >= 10 * 1000 * 1000 = printf "%.0f million" (n / (1000 * 1000))
180showLarge n | n >= 1000 * 1000 = printf "%.1f million" (n / (1000 * 1000))
181showLarge n | n >= 10 * 1000 = printf "%.0f thousand" (n / 1000)
182showLarge n | n >= 10 = unpack $ commasF 0 n
183showLarge n = printf "%.3f" n
184
175countdownWidget :: Bool -> LocalTime -> Widget n 185countdownWidget :: Bool -> LocalTime -> Widget n
176countdownWidget isSimulated (truncateTime -> t) = 186countdownWidget isSimulated (truncateTime -> t) =
177 (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $ 187 (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $
@@ -194,13 +204,14 @@ countdownWidget isSimulated (truncateTime -> t) =
194 (commas secondsLeft) 204 (commas secondsLeft)
195 (pluralize secondsLeft) 205 (pluralize secondsLeft)
196 (pluralizeVerb secondsLeft))) 206 (pluralizeVerb secondsLeft)))
197 , (borderWithLabel (str "Cosmic Countdown") $ 207 , (borderWithLabel (str "Cosmic Time") $
198 vBox [ (str $ printf "%s years ago" (commas $ (floor cosmicYearsAgo :: Integer))) 208 vBox [ (str $ printf "%s years ago" (commas $ (floor cosmicYearsAgo :: Integer)))
199 , (str "\n\n") 209 , (str "\n\n")
210 , (str $ printf "%s years ago" (showLarge $ (realToFrac cosmicYearsAgo)))
200 -- , (str $ printf "%s billion years ago" (commasF 9 $ cosmicYearsAgo / (1000*1000*1000))) 211 -- , (str $ printf "%s billion years ago" (commasF 9 $ cosmicYearsAgo / (1000*1000*1000)))
201 -- , (str $ printf "%s million years ago" (commasF 6 $ cosmicYearsAgo / (1000*1000))) 212 -- , (str $ printf "%s million years ago" (commasF 6 $ cosmicYearsAgo / (1000*1000)))
202 -- , (str $ printf "%s thousand years ago" (commasF 3 $ cosmicYearsAgo / 1000)) 213 -- , (str $ printf "%s thousand years ago" (commasF 3 $ cosmicYearsAgo / 1000))
203 , (str $ printf "%s days ago" (commas $ (floor $ realToFrac cosmicYearsAgo * daysPerYear :: Integer))) 214 -- , (str $ printf "%s days ago" (commas $ (floor $ realToFrac cosmicYearsAgo * daysPerYear :: Integer)))
204 ]) 215 ])
205 ]) 216 ])
206 , 217 ,
diff --git a/package.yaml b/package.yaml
index fa26a44..d081cde 100644
--- a/package.yaml
+++ b/package.yaml
@@ -12,6 +12,7 @@ dependencies:
12- containers 12- containers
13- brick 13- brick
14- format-numbers 14- format-numbers
15- text
15 16
16executables: 17executables:
17 countdown: 18 countdown: