From bafc1849b9e5a4196036305b4dbe1a3f51155721 Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sat, 17 Sep 2022 10:49:21 -0400 Subject: cleanups --- CosmicCalendar.hs | 43 ++++++++++++++++++++++--------------------- countdown.hs | 5 ----- 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 { } deriving (Show) -- TODO: Encode the input times like so: -data CosmicTime = YearsAgo Rational | YearsAfterBigBang Rational | YearsBCE Rational | YearsCE Rational --- We need the Map data structure to have a simple ordering... --- We could simply regenerate the entire table as a function of the year. --- This would also allow to fudge the last day countdown to be identical on leap years. --- "YearsAgo" would measure from the end of the year on a 365 day model even on 366 day years. --- Another option is to keep it 365-based, but on leap years fudge every day after Feb 29 when we use the calendar... --- I.e. the getNextCalendarEntry functions would subtract a day from the input value starting March 1. --- But this still doesn't allow to encode such dates as `YearsCE 1492` for Columbus. +-- +-- data CosmicTime = YearsAgo Rational | YearsAfterBigBang Rational | YearsBCE Rational | YearsCE Rational +-- +-- The absolute time values (YearsBCE and YearsCE) will be computed using the +-- year at program start: + +currentYear :: Integer +currentYear = unsafePerformIO $ getZonedTime <&> toGregorian . localDay . zonedTimeToLocalTime <&> view _1 theCalendar :: Map NominalDiffTime CalendarEntry theCalendar = Map.fromList $ map (\x -> (calBeginTime x, x)) theCalendarList +years :: Rational -> NominalDiffTime +years = (* lengthOfYear) . fromRational + +yearsAgo :: Rational -> NominalDiffTime +yearsAgo (fromRational -> n) = lengthOfYear * (1 - (n / fromIntegral ageOfUniverseInYears)) + +afterBigBang :: NominalDiffTime -> NominalDiffTime +afterBigBang = (/ ageOfUniverse) . (* lengthOfYear) + thousandYears :: Rational -> NominalDiffTime -thousandYears = (* (lengthOfYear * 1000)) . fromRational +thousandYears = years . (* 1000) millionYears :: Rational -> NominalDiffTime -millionYears = (* (lengthOfYear * 1000 * 1000)) . fromRational +millionYears = thousandYearsAgo . (* 1000) billionYears :: Rational -> NominalDiffTime -billionYears = (* (lengthOfYear * 1000 * 1000 * 1000)) . fromRational - -yearsAgo :: Rational -> NominalDiffTime -yearsAgo (fromRational -> n) = lengthOfYear' * (1 - (n / fromIntegral ageOfUniverseInYears)) - where - lengthOfYear' = 365 * lengthOfDay -- TODO: Countdown will be wrong day on leap years! +billionYears = millionYearsAgo . (* 1000) thousandYearsAgo :: Rational -> NominalDiffTime thousandYearsAgo = yearsAgo . (* 1000) @@ -100,9 +104,6 @@ millionYearsAgo = thousandYearsAgo . (* 1000) billionYearsAgo :: Rational -> NominalDiffTime billionYearsAgo = millionYearsAgo . (* 1000) -afterBigBang :: NominalDiffTime -> NominalDiffTime -afterBigBang = (/ ageOfUniverse) . (* lengthOfYear) - yearStart :: LocalTime -> LocalTime yearStart (LocalTime d _) = LocalTime d' t' where @@ -529,8 +530,8 @@ Named Nyasasaurus parringtoni, the roughly 243-million-year-old fossils represen ] where - theYear = yearsAgo . (2022 -) - yearsBeforeCommonEra n = yearsAgo (2022 + n) + theYear = yearsAgo . toRational . (currentYear -) + yearsBeforeCommonEra = yearsAgo . toRational . ((+) (currentYear - 1)) earthDescription = [text| 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] 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 = borderWithLabel (str "Cosmic Conversion") (hBox [cosmicConversion, cosmicConversion']) ]) where - cosmicCalendarCurrent = - borderWithLabel (str $ printf "%s on the Cosmic Calendar" (if currentEntryIsCurrent then "Now" else "Previously" :: Text)) - currentEntry - cosmicCalendarNext = borderWithLabel (txt "Next on the Cosmic Calendar") nextEntry - -- TODO: We want to display "today" or "now" on the cosmic calendar; -- We want to display what happened previously on the cosmic calendar -- We want to say how long ago the previous happening was relative to today's date and today's place on the cosmic calendar -- cgit v1.2.3