aboutsummaryrefslogtreecommitdiff
path: root/cmd
diff options
context:
space:
mode:
authorIgor Pashev <pashev.igor@gmail.com>2021-05-13 12:07:51 +0200
committerIgor Pashev <pashev.igor@gmail.com>2021-05-13 12:07:51 +0200
commitda04a198a6c6806aa9502121c3a8ae52767229e0 (patch)
tree437748ac5dc2e565c3b1dc24ec4cd6975319e647 /cmd
parentbf844972aad8839d430be88b14097fd4cdaec059 (diff)
downloadopenweathermap-da04a198a6c6806aa9502121c3a8ae52767229e0.tar.gz
Print local time
Diffstat (limited to 'cmd')
-rw-r--r--cmd/Print.hs19
1 files changed, 14 insertions, 5 deletions
diff --git a/cmd/Print.hs b/cmd/Print.hs
index 7a87023..e27fa90 100644
--- a/cmd/Print.hs
+++ b/cmd/Print.hs
@@ -23,6 +23,8 @@ printCurrectWeather :: CW.CurrentWeather -> IO ()
printCurrectWeather cw =
putStrLn
(place ++
+ ", " ++
+ time ++
": " ++
intercalate
", "
@@ -34,6 +36,8 @@ printCurrectWeather cw =
, showWind wind
])
where
+ tz = secondsToTimeZone (CW.timezone cw)
+ time = showLocalTime tz (CW.dt cw)
w = showWeather $ CW.weather cw
place = showLocation (CW.name cw) (Sys.country . CW.sys $ cw) (CW.coord cw)
mainw = CW.main cw
@@ -42,14 +46,17 @@ printCurrectWeather cw =
printForecastWeather :: FW.ForecastWeather -> IO ()
printForecastWeather fw = do
let c = FW.city fw
- tz = minutesToTimeZone (City.timezone c `div` 60)
+ tz = secondsToTimeZone (City.timezone c)
place = showLocation (City.name c) (City.country c) (City.coord c)
putStrLn place
mapM_ putStrLn (showForecast tz <$> FW.list fw)
+secondsToTimeZone :: Int -> TimeZone
+secondsToTimeZone s = minutesToTimeZone (s `div` 60)
+
showForecast :: TimeZone -> FC.Forecast -> String
showForecast tz fc =
- localtime ++
+ showLocalTime tz (FC.dt fc) ++
": " ++
intercalate
", "
@@ -61,10 +68,12 @@ showForecast tz fc =
, showWind (FC.wind fc)
]
where
- localtime =
- show . utcToZonedTime tz . posixSecondsToUTCTime . fromIntegral $ FC.dt fc
mainw = FC.main fc
+showLocalTime :: TimeZone -> Int -> String
+showLocalTime tz =
+ show . utcToZonedTime tz . posixSecondsToUTCTime . fromIntegral
+
showLocation :: String -> Maybe String -> Coord.Coord -> String
showLocation name country coord =
name' ++ maybe "" ("," ++) country ++ " " ++ coords
@@ -82,7 +91,7 @@ showCoord coord =
"°, " ++ maybe "?" show (Coord.lon coord) ++ "°)"
showWeather :: [Weather.Weather] -> String
-showWeather w = intercalate "," $ Weather.main <$> w
+showWeather w = intercalate "/" $ Weather.main <$> w
showHumidity :: Main.Main -> String
showHumidity m = "H " ++ show hm ++ " %"