diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-15 21:04:32 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-15 21:04:32 -0400 |
commit | b780b57488c5caf277609880f9a6e62f4a38de9b (patch) | |
tree | 8e2b6a770f9733730ec14687f8021bdc18e4e136 | |
parent | 99196ea09ccc07574c3b1233d7885fbc1f934d5f (diff) |
add cosmic conversion table
-rwxr-xr-x | countdown.hs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/countdown.hs b/countdown.hs index e2a667e..1cf7a55 100755 --- a/countdown.hs +++ b/countdown.hs | |||
@@ -53,6 +53,7 @@ import Brick.Widgets.Core | |||
53 | import Brick.AttrMap as A | 53 | import Brick.AttrMap as A |
54 | import Brick.Util (fg, bg, on, clamp) | 54 | import Brick.Util (fg, bg, on, clamp) |
55 | import Brick.Widgets.Core | 55 | import Brick.Widgets.Core |
56 | import Brick.Widgets.Table | ||
56 | 57 | ||
57 | billion :: Integer | 58 | billion :: Integer |
58 | billion = 1000 * 1000 * 1000 | 59 | billion = 1000 * 1000 * 1000 |
@@ -135,6 +136,28 @@ drawUI st = [a] | |||
135 | 136 | ||
136 | printRemain unit quantity = printf "%d %s%s remain%s" | 137 | printRemain unit quantity = printf "%d %s%s remain%s" |
137 | 138 | ||
139 | showTime :: NominalDiffTime -> String | ||
140 | showTime t | t < 1 = printf "%.3f seconds" (realToFrac t :: Float) | ||
141 | showTime t | t == 1 = "1 second" | ||
142 | -- showTime t | t < 10 = formatTime defaultTimeLocale "%2Es seconds" t -- BUG! Doesn't respect <width> parameter at all! | ||
143 | showTime t | t < 10 = printf "%.2f seconds" (realToFrac t :: Float) | ||
144 | showTime t | t < 60 = printf "%.1f seconds" (realToFrac t :: Float) | ||
145 | showTime t | t == 60 = formatTime defaultTimeLocale "%M minute" t | ||
146 | showTime t | t < 60*10 = formatTime defaultTimeLocale "%M minutes %Ss" t | ||
147 | showTime t | t < 60*60 = formatTime defaultTimeLocale "%M minutes" t | ||
148 | showTime t | t == 60*60 = "1 hour" | ||
149 | showTime t | t < 60*60*2 = formatTime defaultTimeLocale "%H hour %Mm" t | ||
150 | showTime t | t < 60*60*24 = formatTime defaultTimeLocale "%H hours %Mm" t | ||
151 | showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t | ||
152 | showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t | ||
153 | showTime t = formatTime defaultTimeLocale "%d days" t | ||
154 | -- showTime t = formatTime defaultTimeLocale "%w weeks %D days" t | ||
155 | |||
156 | yearsToCosmicTime :: Integral i => i -> NominalDiffTime | ||
157 | yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . realToFrac | ||
158 | |||
159 | showCosmicYears = str . showTime . yearsToCosmicTime | ||
160 | |||
138 | countdownWidget :: Bool -> LocalTime -> Widget n | 161 | countdownWidget :: Bool -> LocalTime -> Widget n |
139 | countdownWidget isSimulated (truncateTime -> t) = | 162 | countdownWidget isSimulated (truncateTime -> t) = |
140 | (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $ | 163 | (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $ |
@@ -169,6 +192,19 @@ countdownWidget isSimulated (truncateTime -> t) = | |||
169 | ]) | 192 | ]) |
170 | ]) | 193 | ]) |
171 | <=> | 194 | <=> |
195 | (borderWithLabel (str "Cosmic Conversion") $ renderTable $ | ||
196 | table | ||
197 | [ | ||
198 | [str "1 billion years" , showCosmicYears $ 1000 * 1000 * 1000], | ||
199 | [str "100 million years" , showCosmicYears $ 100 * 1000 * 1000], | ||
200 | [str "10 million years" , showCosmicYears $ 10 * 1000 * 1000], | ||
201 | [str "1 million years" , showCosmicYears $ 1000 * 1000], | ||
202 | [str "100 thousand years" , showCosmicYears $ 100 * 1000], | ||
203 | [str "10 thousand years" , showCosmicYears $ 10 * 1000], | ||
204 | [str "1 thousand years" , showCosmicYears 1000], | ||
205 | [str "100 years" , showCosmicYears 100] | ||
206 | ]) | ||
207 | <=> | ||
172 | (borderWithLabel (str progressLabel) $ | 208 | (borderWithLabel (str progressLabel) $ |
173 | updateAttrMap | 209 | updateAttrMap |
174 | (A.mapAttrName yDoneAttr P.progressCompleteAttr . | 210 | (A.mapAttrName yDoneAttr P.progressCompleteAttr . |