diff options
author | Andrew Cady <d@cryptonomic.net> | 2022-09-15 10:01:18 -0400 |
---|---|---|
committer | Andrew Cady <d@cryptonomic.net> | 2022-09-15 10:01:18 -0400 |
commit | 6e10d8246eabad813b45a2e444250985a6dd79f8 (patch) | |
tree | ee5a34e9651157ca943874223a87e3d02f44481f | |
parent | 55578931c978445a164ec38876e21a33a1abc356 (diff) |
refactor
-rwxr-xr-x | countdown.hs | 92 |
1 files changed, 50 insertions, 42 deletions
diff --git a/countdown.hs b/countdown.hs index b976e73..ffe7af0 100755 --- a/countdown.hs +++ b/countdown.hs | |||
@@ -112,48 +112,56 @@ pluralizeVerb _ = "" | |||
112 | 112 | ||
113 | drawUI :: St -> [Widget ()] | 113 | drawUI :: St -> [Widget ()] |
114 | drawUI st = [a] | 114 | drawUI st = [a] |
115 | where | 115 | where |
116 | t = utcToZonedTime zone $ st ^. stCurrentTime | 116 | a = (str $ "Last event: " <> (show $ st^.stLastBrickEvent)) |
117 | currentYear = yearNumber t | 117 | <=> |
118 | dayNum = dayNumOfYear t | 118 | (str "\n") |
119 | numDays = daysInYear t | 119 | <=> |
120 | yearLength = fromIntegral numDays * nominalDay | 120 | (countdownWidget $ utcToZonedTime zone $ st ^. stCurrentTime) |
121 | -- yearLength = (zonedTimeToLocalTime $ yearEnd t) `diffLocalTime` (zonedTimeToLocalTime $ yearStart t) | 121 | |
122 | yearElapsed = (zonedTimeToLocalTime t) `diffLocalTime` (zonedTimeToLocalTime $ yearStart t) | 122 | countdownWidget :: ZonedTime -> Widget n |
123 | 123 | countdownWidget t = | |
124 | daysLeft = numDays - dayNum | 124 | (hCenter (borderWithLabel (str "Current time") $ |
125 | secondsLeft = toSeconds $ yearLength - yearElapsed | 125 | (str (formatTime defaultTimeLocale "%A, %B %e%n%Y-%m-%d %r" t)))) |
126 | a = -- (str $ "Last event: " <> (show $ st^.stLastBrickEvent)) | 126 | |
127 | -- <=> | 127 | <=> |
128 | (hCenter (borderWithLabel (str "Current time") $ | 128 | (borderWithLabel (str "Progress through year") $ |
129 | (str (formatTime defaultTimeLocale "%A, %B %e%n%Y-%m-%d %r" t)))) | 129 | (str "\n") |
130 | 130 | <=> | |
131 | <=> | 131 | (borderWithLabel (str $ printf "%d" currentYear) |
132 | (borderWithLabel (str "Progress through year") $ | 132 | (str $ printf "%d day%s remain\n%s second%s remain%s" |
133 | (str "\n") | 133 | daysLeft |
134 | <=> | 134 | (pluralize daysLeft) |
135 | (borderWithLabel (str $ printf "%d" currentYear) | 135 | (commas secondsLeft) |
136 | (str $ printf "%d day%s remain\n%s second%s remain%s" | 136 | (pluralize secondsLeft) |
137 | daysLeft | 137 | (pluralizeVerb secondsLeft))) |
138 | (pluralize daysLeft) | 138 | <=> |
139 | (commas secondsLeft) | 139 | (borderWithLabel (str progressLabel) $ |
140 | (pluralize secondsLeft) | 140 | updateAttrMap |
141 | (pluralizeVerb secondsLeft))) | 141 | (A.mapAttrName yDoneAttr P.progressCompleteAttr . |
142 | <=> | 142 | A.mapAttrName yToDoAttr P.progressIncompleteAttr) $ |
143 | (borderWithLabel (str progressLabel) $ | 143 | progressBar Nothing (realToFrac $ yearElapsed // yearLength)) |
144 | updateAttrMap | 144 | <=> |
145 | (A.mapAttrName yDoneAttr P.progressCompleteAttr . | 145 | (hCenter $ str $ printf "\nDay #%d of %d in %d\nSecond #%s of %s in %d" |
146 | A.mapAttrName yToDoAttr P.progressIncompleteAttr) $ | 146 | dayNum |
147 | progressBar Nothing (realToFrac $ yearElapsed // yearLength)) | 147 | numDays |
148 | <=> | 148 | currentYear |
149 | (hCenter $ str $ printf "\nDay #%d of %d\nSecond #%s of %s" | 149 | (commas $ toSeconds yearElapsed) |
150 | dayNum | 150 | (commas $ toSeconds yearLength) |
151 | numDays | 151 | currentYear)) |
152 | (commas $ toSeconds yearElapsed) | 152 | where |
153 | (commas $ toSeconds yearLength))) | 153 | currentYear = yearNumber t |
154 | toSeconds dt = nominalDiffTimeToSeconds dt `div'` 1 :: Int | 154 | dayNum = dayNumOfYear t |
155 | x // y = fromRational $ toRational x / toRational y :: Double | 155 | numDays = daysInYear t |
156 | progressLabel = printf "%.6F%%" (100 * (yearElapsed // yearLength)) | 156 | yearLength = fromIntegral numDays * nominalDay |
157 | -- yearLength = (zonedTimeToLocalTime $ yearEnd t) `diffLocalTime` (zonedTimeToLocalTime $ yearStart t) | ||
158 | yearElapsed = (zonedTimeToLocalTime t) `diffLocalTime` (zonedTimeToLocalTime $ yearStart t) | ||
159 | |||
160 | daysLeft = numDays - dayNum | ||
161 | secondsLeft = toSeconds $ yearLength - yearElapsed | ||
162 | toSeconds dt = nominalDiffTimeToSeconds dt `div'` 1 :: Int | ||
163 | x // y = fromRational $ toRational x / toRational y :: Double | ||
164 | progressLabel = printf "%.6F%%" (100 * (yearElapsed // yearLength)) | ||
157 | 165 | ||
158 | commas :: Integral i => i -> Text | 166 | commas :: Integral i => i -> Text |
159 | commas = prettyI (Just ',') . fromIntegral | 167 | commas = prettyI (Just ',') . fromIntegral |