diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-16 01:13:51 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-16 01:13:51 -0400 |
commit | da257758d5a49fb3d05aa057a5c81e59128ba10b (patch) | |
tree | c50159099579eaa2c064a1c748eb235e6f0b3dcc | |
parent | 24dbb9fbd618a2ba29b48d8bf76c0d5a9a5b3ce3 (diff) |
add second cosmic conversion table
-rwxr-xr-x | countdown.hs | 39 |
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 | |||
142 | showTime t | t == 60*60 = "1 hour" | 142 | showTime t | t == 60*60 = "1 hour" |
143 | showTime t | t < 60*60*2 = formatTime defaultTimeLocale "%H hour %Mm" t | 143 | showTime t | t < 60*60*2 = formatTime defaultTimeLocale "%H hour %Mm" t |
144 | showTime t | t < 60*60*24 = formatTime defaultTimeLocale "%H hours %Mm" t | 144 | showTime t | t < 60*60*24 = formatTime defaultTimeLocale "%H hours %Mm" t |
145 | showTime t | t == 60*60*24 = formatTime defaultTimeLocale "%d day" t | ||
145 | showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t | 146 | showTime t | t < 60*60*24*2 = formatTime defaultTimeLocale "%d day %Hh" t |
147 | showTime t | t == 60*60*24*7 = formatTime defaultTimeLocale "%d days" t | ||
146 | showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t | 148 | showTime t | t < 60*60*24*10 = formatTime defaultTimeLocale "%d days %Hh" t |
147 | showTime t = formatTime defaultTimeLocale "%d days" t | 149 | showTime 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 | |||
153 | showCosmicYears :: Integer -> Widget n | 155 | showCosmicYears :: Integer -> Widget n |
154 | showCosmicYears = str . showTime . yearsToCosmicTime | 156 | showCosmicYears = str . showTime . yearsToCosmicTime |
155 | 157 | ||
158 | toCosmicTime :: NominalDiffTime -> Rational | ||
159 | toCosmicTime t = realToFrac ageOfUniverseInYears * (realToFrac $ t // yearLength) :: Rational | ||
160 | where | ||
161 | yearLength = daysPerYear * nominalDay | ||
162 | x // y = fromRational $ toRational x / toRational y :: Double | ||
163 | |||
164 | conversionTableRowFromCosmicSeconds :: NominalDiffTime -> [Widget n] | ||
165 | conversionTableRowFromCosmicSeconds 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 | |||
171 | cosmicConversion' :: Widget n | ||
172 | cosmicConversion' = 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 | |||
156 | cosmicConversion :: Widget n | 183 | cosmicConversion :: Widget n |
157 | cosmicConversion = borderWithLabel (str "Cosmic Conversion") $ renderTable $ | 184 | cosmicConversion = 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 | ||
170 | showLarge :: Double -> String | 203 | showLarge :: 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 |