aboutsummaryrefslogtreecommitdiff
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
parentbf844972aad8839d430be88b14097fd4cdaec059 (diff)
downloadopenweathermap-da04a198a6c6806aa9502121c3a8ae52767229e0.tar.gz
Print local time
-rw-r--r--cmd/Print.hs19
-rw-r--r--lib/Web/OpenWeatherMap/Types/CurrentWeather.hs1
2 files changed, 15 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 ++ " %"
diff --git a/lib/Web/OpenWeatherMap/Types/CurrentWeather.hs b/lib/Web/OpenWeatherMap/Types/CurrentWeather.hs
index 02d3371..7131dfe 100644
--- a/lib/Web/OpenWeatherMap/Types/CurrentWeather.hs
+++ b/lib/Web/OpenWeatherMap/Types/CurrentWeather.hs
@@ -29,6 +29,7 @@ data CurrentWeather =
, clouds :: Clouds
, dt :: Int
, sys :: Sys
+ , timezone :: Int
, id :: Int
, name :: String
, cod :: Int