mirror of
https://github.com/quantum9Innovation/suntheme.git
synced 2024-11-25 01:43:50 -08:00
4f0db471bc
move time-related functions from `Main.hs` to a new `Time` module for better organization and code separation
28 lines
795 B
Haskell
28 lines
795 B
Haskell
module Time where
|
|
|
|
import Pure (sunriseNext)
|
|
|
|
import Data.Time (ZonedTime, getCurrentTime)
|
|
import Data.Time.Solar (Location(Location), sunrise, sunset)
|
|
import Data.Time.LocalTime (getTimeZone, utcToZonedTime)
|
|
|
|
now :: IO ZonedTime
|
|
now = do
|
|
utcTime <- getCurrentTime
|
|
timeZone <- getTimeZone utcTime
|
|
return (utcToZonedTime timeZone utcTime)
|
|
|
|
sunriseNow :: Double -> Double -> IO ZonedTime
|
|
sunriseNow lat lon = do
|
|
time <- now
|
|
return (sunrise time here)
|
|
where here = Location lat lon
|
|
|
|
sunsetNow :: Double -> Double -> IO ZonedTime
|
|
sunsetNow lat lon = do
|
|
time <- now
|
|
return (sunset time here)
|
|
where here = Location lat lon
|
|
|
|
activateOnSunrise :: ZonedTime -> ZonedTime -> IO Bool
|
|
activateOnSunrise sunriseTime sunsetTime = sunriseNext sunriseTime sunsetTime <$> now
|