summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@cryptonomic.net>2022-09-17 10:49:21 -0400
committerAndrew Cady <d@cryptonomic.net>2022-09-17 10:49:21 -0400
commitbafc1849b9e5a4196036305b4dbe1a3f51155721 (patch)
treec545ac013e451f60d8eb7a503ae040d03835a168
parent3fb2c70d2f7e108dc8b83519c4220667bba13f46 (diff)
cleanups
-rw-r--r--CosmicCalendar.hs43
-rwxr-xr-xcountdown.hs5
2 files changed, 22 insertions, 26 deletions
diff --git a/CosmicCalendar.hs b/CosmicCalendar.hs
index 50566d3..b198328 100644
--- a/CosmicCalendar.hs
+++ b/CosmicCalendar.hs
@@ -65,31 +65,35 @@ data CalendarEntry = CalendarEntry {
65} deriving (Show) 65} deriving (Show)
66 66
67-- TODO: Encode the input times like so: 67-- TODO: Encode the input times like so:
68data CosmicTime = YearsAgo Rational | YearsAfterBigBang Rational | YearsBCE Rational | YearsCE Rational 68--
69-- We need the Map data structure to have a simple ordering... 69-- data CosmicTime = YearsAgo Rational | YearsAfterBigBang Rational | YearsBCE Rational | YearsCE Rational
70-- We could simply regenerate the entire table as a function of the year. 70--
71-- This would also allow to fudge the last day countdown to be identical on leap years. 71-- The absolute time values (YearsBCE and YearsCE) will be computed using the
72-- "YearsAgo" would measure from the end of the year on a 365 day model even on 366 day years. 72-- year at program start:
73-- Another option is to keep it 365-based, but on leap years fudge every day after Feb 29 when we use the calendar... 73
74-- I.e. the getNextCalendarEntry functions would subtract a day from the input value starting March 1. 74currentYear :: Integer
75-- But this still doesn't allow to encode such dates as `YearsCE 1492` for Columbus. 75currentYear = unsafePerformIO $ getZonedTime <&> toGregorian . localDay . zonedTimeToLocalTime <&> view _1
76 76
77theCalendar :: Map NominalDiffTime CalendarEntry 77theCalendar :: Map NominalDiffTime CalendarEntry
78theCalendar = Map.fromList $ map (\x -> (calBeginTime x, x)) theCalendarList 78theCalendar = Map.fromList $ map (\x -> (calBeginTime x, x)) theCalendarList
79 79
80years :: Rational -> NominalDiffTime
81years = (* lengthOfYear) . fromRational
82
83yearsAgo :: Rational -> NominalDiffTime
84yearsAgo (fromRational -> n) = lengthOfYear * (1 - (n / fromIntegral ageOfUniverseInYears))
85
86afterBigBang :: NominalDiffTime -> NominalDiffTime
87afterBigBang = (/ ageOfUniverse) . (* lengthOfYear)
88
80thousandYears :: Rational -> NominalDiffTime 89thousandYears :: Rational -> NominalDiffTime
81thousandYears = (* (lengthOfYear * 1000)) . fromRational 90thousandYears = years . (* 1000)
82 91
83millionYears :: Rational -> NominalDiffTime 92millionYears :: Rational -> NominalDiffTime
84millionYears = (* (lengthOfYear * 1000 * 1000)) . fromRational 93millionYears = thousandYearsAgo . (* 1000)
85 94
86billionYears :: Rational -> NominalDiffTime 95billionYears :: Rational -> NominalDiffTime
87billionYears = (* (lengthOfYear * 1000 * 1000 * 1000)) . fromRational 96billionYears = millionYearsAgo . (* 1000)
88
89yearsAgo :: Rational -> NominalDiffTime
90yearsAgo (fromRational -> n) = lengthOfYear' * (1 - (n / fromIntegral ageOfUniverseInYears))
91 where
92 lengthOfYear' = 365 * lengthOfDay -- TODO: Countdown will be wrong day on leap years!
93 97
94thousandYearsAgo :: Rational -> NominalDiffTime 98thousandYearsAgo :: Rational -> NominalDiffTime
95thousandYearsAgo = yearsAgo . (* 1000) 99thousandYearsAgo = yearsAgo . (* 1000)
@@ -100,9 +104,6 @@ millionYearsAgo = thousandYearsAgo . (* 1000)
100billionYearsAgo :: Rational -> NominalDiffTime 104billionYearsAgo :: Rational -> NominalDiffTime
101billionYearsAgo = millionYearsAgo . (* 1000) 105billionYearsAgo = millionYearsAgo . (* 1000)
102 106
103afterBigBang :: NominalDiffTime -> NominalDiffTime
104afterBigBang = (/ ageOfUniverse) . (* lengthOfYear)
105
106yearStart :: LocalTime -> LocalTime 107yearStart :: LocalTime -> LocalTime
107yearStart (LocalTime d _) = LocalTime d' t' 108yearStart (LocalTime d _) = LocalTime d' t'
108 where 109 where
@@ -529,8 +530,8 @@ Named Nyasasaurus parringtoni, the roughly 243-million-year-old fossils represen
529 ] 530 ]
530 531
531 where 532 where
532 theYear = yearsAgo . (2022 -) 533 theYear = yearsAgo . toRational . (currentYear -)
533 yearsBeforeCommonEra n = yearsAgo (2022 + n) 534 yearsBeforeCommonEra = yearsAgo . toRational . ((+) (currentYear - 1))
534 earthDescription = [text| 535 earthDescription = [text|
535 The standard model for the formation of the Solar System (including the Earth) is the solar nebula hypothesis.[23] In this model, the Solar System formed from a large, rotating cloud of interstellar dust and gas called the solar nebula. It was composed of hydrogen and helium created shortly after the Big Bang 13.8 Ga (billion years ago) and heavier elements ejected by supernovae. About 4.5 Ga, the nebula began a contraction that may have been triggered by the shock wave from a nearby supernova.[24] A shock wave would have also made the nebula rotate. As the cloud began to accelerate, its angular momentum, gravity, and inertia flattened it into a protoplanetary disk perpendicular to its axis of rotation. Small perturbations due to collisions and the angular momentum of other large debris created the means by which kilometer-sized protoplanets began to form, orbiting the nebular center.[25] 536 The standard model for the formation of the Solar System (including the Earth) is the solar nebula hypothesis.[23] In this model, the Solar System formed from a large, rotating cloud of interstellar dust and gas called the solar nebula. It was composed of hydrogen and helium created shortly after the Big Bang 13.8 Ga (billion years ago) and heavier elements ejected by supernovae. About 4.5 Ga, the nebula began a contraction that may have been triggered by the shock wave from a nearby supernova.[24] A shock wave would have also made the nebula rotate. As the cloud began to accelerate, its angular momentum, gravity, and inertia flattened it into a protoplanetary disk perpendicular to its axis of rotation. Small perturbations due to collisions and the angular momentum of other large debris created the means by which kilometer-sized protoplanets began to form, orbiting the nebular center.[25]
536 537
diff --git a/countdown.hs b/countdown.hs
index 54f79f5..5080649 100755
--- a/countdown.hs
+++ b/countdown.hs
@@ -220,11 +220,6 @@ countdownWidget isSimulated t =
220 borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion']) 220 borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion'])
221 ]) 221 ])
222 where 222 where
223 cosmicCalendarCurrent =
224 borderWithLabel (str $ printf "%s on the Cosmic Calendar" (if currentEntryIsCurrent then "Now" else "Previously" :: Text))
225 currentEntry
226 cosmicCalendarNext = borderWithLabel (txt "Next on the Cosmic Calendar") nextEntry
227
228 -- TODO: We want to display "today" or "now" on the cosmic calendar; 223 -- TODO: We want to display "today" or "now" on the cosmic calendar;
229 -- We want to display what happened previously on the cosmic calendar 224 -- We want to display what happened previously on the cosmic calendar
230 -- We want to say how long ago the previous happening was relative to today's date and today's place on the cosmic calendar 225 -- We want to say how long ago the previous happening was relative to today's date and today's place on the cosmic calendar