From da04a198a6c6806aa9502121c3a8ae52767229e0 Mon Sep 17 00:00:00 2001 From: Igor Pashev Date: Thu, 13 May 2021 12:07:51 +0200 Subject: Print local time --- cmd/Print.hs | 19 ++++++++++++++----- lib/Web/OpenWeatherMap/Types/CurrentWeather.hs | 1 + 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 -- cgit v1.2.3