diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2015-04-05 20:26:19 +0900 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2015-04-05 20:26:19 +0900 |
commit | 7fa6579581b6734595b0d028056998b1c96f4af4 (patch) | |
tree | cf81b3589b62c197277c431bfa5a2ce8012caf65 /src/Utility/EventCache.hs | |
parent | ef6658144244e5dcb319a21cfc6dbe706c7ea0be (diff) | |
download | srem-7fa6579581b6734595b0d028056998b1c96f4af4.tar.gz |
timetable reminders functionality for school
Diffstat (limited to 'src/Utility/EventCache.hs')
-rw-r--r-- | src/Utility/EventCache.hs | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/src/Utility/EventCache.hs b/src/Utility/EventCache.hs index a5835db..000a3cd 100644 --- a/src/Utility/EventCache.hs +++ b/src/Utility/EventCache.hs @@ -26,19 +26,25 @@ module Utility.EventCache ( purgeOldEventCaches , refreshEmacsEventCache , readEmacsEventCache , readManualEventCache + , getTimetableReminders ) where import Control.Applicative ((<$>)) import Control.Exception (IOException, catch) import Control.Monad (filterM, forM_, when) import qualified Control.SremConfig as SremConfig -import Data.List.Split (splitOn, splitOneOf) +import Data.Char (toLower) import Data.Maybe.Read import Data.Time.Calendar +import Data.Time.Format import Data.Time.LocalTime import System.Directory (createDirectoryIfMissing, doesFileExist, getDirectoryContents, removeFile) import System.FilePath ((</>)) +import System.Locale (defaultTimeLocale) + +import Data.List.Split (splitOn, splitOneOf) + import Types.Reminder import Utility.Emacs @@ -94,6 +100,17 @@ readManualEventCache = do then readEventsCSV path else return [] +getTimetableReminders :: IO [Reminder] +getTimetableReminders = do + dayOfWeek <- map toLower . formatTime defaultTimeLocale "%A" + . localDay . zonedTimeToLocalTime <$> getZonedTime + dir <- SremConfig.getCacheDirectory + let path = dir </> dayOfWeek ++ ".csv" + exists <- doesFileExist path + if exists + then readEventsCSV path + else return [] + -- #### Internal functions readEventsCSV :: FilePath -> IO [Reminder] |