summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-16 01:13:51 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-16 01:13:51 -0400
commitda257758d5a49fb3d05aa057a5c81e59128ba10b (patch)
treec50159099579eaa2c064a1c748eb235e6f0b3dcc
parent24dbb9fbd618a2ba29b48d8bf76c0d5a9a5b3ce3 (diff)
add second cosmic conversion table
-rwxr-xr-xcountdown.hs39
1 files changed, 36 insertions, 3 deletions
diff --git a/countdown.hs b/countdown.hs
index afd9266..ac5193b 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -142,7 +142,9 @@ showTime t | t < 60*60 = formatTime defaultTimeLocale "%M minutes" t
142showTime t | t == 60*60 = "1 hour" 142showTime t | t == 60*60 = "1 hour"
143showTime t | t < 60*60*2 = formatTime defaultTimeLocale "%H hour %Mm" t 143showTime t | t < 60*60*2 = formatTime defaultTimeLocale "%H hour %Mm" t
144showTime t | t < 60*60*24 = formatTime defaultTimeLocale "%H hours %Mm" t 144showTime t | t < 60*60*24 = formatTime defaultTimeLocale "%H hours %Mm" t
145showTime t | t == 60*60*24 = formatTime defaultTimeLocale "%d day" t
145showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t 146showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t
147showTime t | t == 60*60*24*7 = formatTime defaultTimeLocale "%d days" t
146showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t 148showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t
147showTime t = formatTime defaultTimeLocale "%d days" t 149showTime t = formatTime defaultTimeLocale "%d days" t
148-- showTime t = formatTime defaultTimeLocale "%w weeks %D days" t 150-- showTime t = formatTime defaultTimeLocale "%w weeks %D days" t
@@ -153,18 +155,49 @@ yearsToCosmicTime = (/ (realToFrac ageOfUniverseInYears)) . (* lengthOfYear) . r
153showCosmicYears :: Integer -> Widget n 155showCosmicYears :: Integer -> Widget n
154showCosmicYears = str . showTime . yearsToCosmicTime 156showCosmicYears = str . showTime . yearsToCosmicTime
155 157
158toCosmicTime :: NominalDiffTime -> Rational
159toCosmicTime t = realToFrac ageOfUniverseInYears * (realToFrac $ t // yearLength) :: Rational
160 where
161 yearLength = daysPerYear * nominalDay
162 x // y = fromRational $ toRational x / toRational y :: Double
163
164conversionTableRowFromCosmicSeconds :: NominalDiffTime -> [Widget n]
165conversionTableRowFromCosmicSeconds n = [cosmicTime, realTime]
166 where
167 realTime = str $ showLarge (fromRational $ toCosmicTime n) ++ " years"
168 -- cosmicTime = showCosmicYears $ ceiling $ toCosmicTime n
169 cosmicTime = str $ showTime n
170
171cosmicConversion' :: Widget n
172cosmicConversion' = renderTable $
173 table
174 [
175 conversionTableRowFromCosmicSeconds $ 30 * 24 * 60 * 60,
176 conversionTableRowFromCosmicSeconds $ 7 * 24 * 60 * 60,
177 conversionTableRowFromCosmicSeconds $ 24 * 60 * 60,
178 conversionTableRowFromCosmicSeconds $ 60 * 60,
179 conversionTableRowFromCosmicSeconds $ 60,
180 conversionTableRowFromCosmicSeconds $ 1
181 ]
182
156cosmicConversion :: Widget n 183cosmicConversion :: Widget n
157cosmicConversion = borderWithLabel (str "Cosmic Conversion") $ renderTable $ 184cosmicConversion = renderTable $
158 table 185 table
159 [ 186 [
160 [str "1 billion years" , showCosmicYears $ 1000 * 1000 * 1000], 187 [str "1 billion years" , showCosmicYears $ 1000 * 1000 * 1000],
188 -- conversionTableRowFromCosmicSeconds $ 7 * 24 * 60 * 60,
161 [str "100 million years" , showCosmicYears $ 100 * 1000 * 1000], 189 [str "100 million years" , showCosmicYears $ 100 * 1000 * 1000],
190 -- conversionTableRowFromCosmicSeconds $ 24 * 60 * 60,
162 [str "10 million years" , showCosmicYears $ 10 * 1000 * 1000], 191 [str "10 million years" , showCosmicYears $ 10 * 1000 * 1000],
192 -- conversionTableRowFromCosmicSeconds $ 60 * 60,
163 [str "1 million years" , showCosmicYears $ 1000 * 1000], 193 [str "1 million years" , showCosmicYears $ 1000 * 1000],
164 [str "100 thousand years" , showCosmicYears $ 100 * 1000], 194 [str "100 thousand years" , showCosmicYears $ 100 * 1000],
195 -- conversionTableRowFromCosmicSeconds $ 60,
165 [str "10 thousand years" , showCosmicYears $ 10 * 1000], 196 [str "10 thousand years" , showCosmicYears $ 10 * 1000],
166 [str "1 thousand years" , showCosmicYears 1000], 197 [str "1 thousand years" , showCosmicYears 1000],
167 [str "100 years" , showCosmicYears 100] 198 [str "100 years" , showCosmicYears 100],
199 [str "10 years" , showCosmicYears 10],
200 [str "1 year" , showCosmicYears 1]
168 ] 201 ]
169 202
170showLarge :: Double -> String 203showLarge :: Double -> String
@@ -230,7 +263,7 @@ countdownWidget isSimulated t =
230 , 263 ,
231 str " " 264 str " "
232 , 265 ,
233 cosmicConversion 266 borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion'])
234 ]) 267 ])
235 where 268 where
236 cosmicYearsAgo = realToFrac ageOfUniverseInYears * (realToFrac $ 1 - (yearElapsed // yearLength)) :: Rational 269 cosmicYearsAgo = realToFrac ageOfUniverseInYears * (realToFrac $ 1 - (yearElapsed // yearLength)) :: Rational