summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-16 16:18:41 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-16 16:18:41 -0400
commit969412bea376b3ff70d60465d2c18a75aadc2e47 (patch)
tree01798ad70eeb157f9222d5386d2e6e0f100bd02e
parent220af07dc4544705919eab6e6bf46aeaf8453db1 (diff)
tweak output
-rwxr-xr-xcountdown.hs98
1 files changed, 63 insertions, 35 deletions
diff --git a/countdown.hs b/countdown.hs
index a446555..7f54920 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -188,36 +188,12 @@ showLarge n = printf "%.3f" n
188 188
189countdownWidget :: Bool -> LocalTime -> Widget n 189countdownWidget :: Bool -> LocalTime -> Widget n
190countdownWidget isSimulated t = 190countdownWidget isSimulated t =
191 (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $
192 padLeftRight 3 $ (str (formatTime defaultTimeLocale "%A, %B %e%n%Y-%m-%d %r" t))))
193
194 <=>
195 (border $ vBox [ 191 (border $ vBox [
196 (hCenter $ hBox 192 (hCenter $ hBox
197 [ (borderWithLabel (str $ printf "Countdown %d" currentYear) 193 [ countdownBox
198 (str $ printf "%d day%s remain%s\n%s hour%s remain%s\n%s minute%s remain%s\n%s second%s remain%s" 194 , currentTimeBox
199 daysLeft 195 , cosmicTimeBox
200 (pluralize daysLeft) 196 ])
201 (pluralizeVerb daysLeft)
202 (commasF 2 hoursLeft)
203 (pluralize $ (floor hoursLeft :: Integer))
204 (pluralizeVerb $ (floor hoursLeft :: Integer))
205 (commasF 2 minutesLeft)
206 (pluralize $ (floor minutesLeft :: Integer))
207 (pluralizeVerb $ (floor minutesLeft :: Integer))
208 (commasF' 1 secondsLeft)
209 (pluralize secondsLeft)
210 (pluralizeVerb secondsLeft)))
211 , (borderWithLabel (str "Cosmic Time") $
212 vBox [ (str $ printf "%s years ago" (commas $ (floor cosmicYearsAgo :: Integer)))
213 , (str "\n\n")
214 , (str $ printf "%s years ago" (showLarge $ (realToFrac cosmicYearsAgo)))
215 -- , (str $ printf "%s billion years ago" (commasF 9 $ cosmicYearsAgo / (1000*1000*1000)))
216 -- , (str $ printf "%s million years ago" (commasF 6 $ cosmicYearsAgo / (1000*1000)))
217 -- , (str $ printf "%s thousand years ago" (commasF 3 $ cosmicYearsAgo / 1000))
218 -- , (str $ printf "%s days ago" (commas $ (floor $ realToFrac cosmicYearsAgo * daysPerYear :: Integer)))
219 ])
220 ])
221 , 197 ,
222 str "\n" 198 str "\n"
223 , 199 ,
@@ -231,18 +207,70 @@ countdownWidget isSimulated t =
231 str "\n" 207 str "\n"
232 <=> 208 <=>
233 hCenter (hBox [ 209 hCenter (hBox [
234 borderWithLabel (str $ printf "Progress through %d" currentYear) $ 210 -- borderWithLabel (str $ printf "Progress through %d" currentYear) $
235 (str $ printf "Day %d of %d\nSecond %s of %s" 211 -- (str $ printf "Day %d of %d; %d remaining\nSecond %s of %s"
236 dayNum 212 -- dayNum
237 numDays 213 -- numDays
238 (commas $ (1 + toSeconds yearElapsed :: Int)) 214 -- (numDays - dayNum)
239 (commas $ toSeconds yearLength)) 215 -- (commas $ (1 + toSeconds yearElapsed :: Int))
240 , 216 -- (commas $ toSeconds yearLength))
217 -- ,
241 str " " 218 str " "
242 , 219 ,
243 borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion']) 220 borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion'])
244 ]) 221 ])
245 where 222 where
223 countdownBox =
224 (borderWithLabel (str $ printf "Countdown %d" currentYear) $
225 (str $ printf "Day %d of %d; %d remaining\nSecond %s of %s"
226 dayNum
227 numDays
228 daysLeft
229 (commas $ (1 + toSeconds yearElapsed :: Int))
230 (commas $ toSeconds yearLength))
231 <=>
232 -- (str $ printf "%d day%s remain%s"
233 -- daysLeft
234 -- (pluralize daysLeft)
235 -- (pluralizeVerb daysLeft)
236 -- )
237 -- <=>
238 (str $ if hoursLeft < 24 && hoursLeft > 1
239 then
240 printf "%s hour%s remain%s"
241 (commasF 2 hoursLeft)
242 (pluralize $ (floor hoursLeft :: Integer))
243 (pluralizeVerb $ (floor hoursLeft :: Integer))
244 else "")
245 <=>
246 (str $ if hoursLeft <= 1 && minutesLeft > 1
247 then
248 printf "%s minute%s remain%s"
249 (commasF 2 minutesLeft)
250 (pluralize $ (floor minutesLeft :: Integer))
251 (pluralizeVerb $ (floor minutesLeft :: Integer))
252 else "")
253 <=>
254 (str $ if minutesLeft <= 1
255 then
256 printf "%s second%s remain%s"
257 (commasF' 1 secondsLeft)
258 (pluralize secondsLeft)
259 (pluralizeVerb secondsLeft)
260 else ""))
261
262 cosmicTimeBox =
263 (borderWithLabel (str "Cosmic Time") $
264 vBox [ (str $ printf "%s years ago" (commas $ (floor cosmicYearsAgo :: Integer)))
265 , (str "\n")
266 , (str $ printf "%s years ago" (showLarge $ (realToFrac cosmicYearsAgo)))
267 -- , (str $ printf "%s billion years ago" (commasF 9 $ cosmicYearsAgo / (1000*1000*1000)))
268 -- , (str $ printf "%s million years ago" (commasF 6 $ cosmicYearsAgo / (1000*1000)))
269 -- , (str $ printf "%s thousand years ago" (commasF 3 $ cosmicYearsAgo / 1000))
270 -- , (str $ printf "%s days ago" (commas $ (floor $ realToFrac cosmicYearsAgo * daysPerYear :: Integer)))
271 ])
272 currentTimeBox = (hCenter (borderWithLabel (str $ printf "Current time%s" (if isSimulated then " (SIMULATED)" else "")) $
273 padLeftRight 3 $ (str (formatTime defaultTimeLocale "%A, %B %e%n%Y-%m-%d %r" t))))
246 cosmicYearsAgo = realToFrac ageOfUniverseInYears * (realToFrac $ 1 - (yearElapsed // yearLength)) :: Rational 274 cosmicYearsAgo = realToFrac ageOfUniverseInYears * (realToFrac $ 1 - (yearElapsed // yearLength)) :: Rational
247 -- cosmicYearsAgo = if yearElapsed == yearLength 275 -- cosmicYearsAgo = if yearElapsed == yearLength
248 -- then 0 276 -- then 0