aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2015-03-31 07:11:19 +0900
committerSean Whitton <spwhitton@spwhitton.name>2015-03-31 07:11:19 +0900
commit82dee866a4af3db1943c26ead9b9310b2dc5ab4b (patch)
treec52619096e7b4e220ba5eaf6b25fa34a3430cb8a
parente5ea1006d9f5e5202b058c8e342d186df2db07ca (diff)
downloadsrem-82dee866a4af3db1943c26ead9b9310b2dc5ab4b.tar.gz
fill out more of Main.hs inc. a big comment
-rw-r--r--src/Main.hs40
-rw-r--r--src/Types/Reminder.hs2
2 files changed, 39 insertions, 3 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 7e55e01..446572f 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -22,25 +22,59 @@
-}
import Control.Applicative ((<$>), (<*>))
+import Data.Time.Calendar
+import Data.Time.LocalTime
import System.Environment (getArgs)
import Types.Reminder
import Utility.EventCache
doCron :: IO ()
-doCron = undefined
+doCron = do
+ rems <- (++) <$> readEmacsEventCache <*> readManualEventCache
+ (h, m, _) <- localHMD
+ let nowRems = filter undefined rems
+ undefined
cmdLineReminder :: [String] -> Maybe Reminder
cmdLineReminder args = undefined
appendUserReminder :: Reminder -> IO ()
-appendUserReminder r = undefined
+appendUserReminder r = do
+ (h, m, d) <- localHMD
+ -- A reminder doesn't know which day the event is on. So we make
+ -- a dummy reminder for right now, and compare to the user's
+ -- input. If their reminder is for a time that's already passed
+ -- today, we save the reminder into tomorrow's cache.
+
+ -- This makes it impossible to set a reminder for more than one
+ -- day into the future ('cmdLineReminder' is a pure function and
+ -- doesn't know what day it is now). But the only way to express
+ -- a reminder for the day after tomorrow in srem's deliberately
+ -- simple command line input would be to write something like
+ -- @srem 1500m Go out to meet Tina@ which no user would want to
+ -- do.
+
+ -- The day after tomorrow is far enough in the future that an
+ -- appointment in Emacs Org-mode should be used instead of srem's
+ -- manual reminder input.
+ let dummyRem = makeReminder' h m (getReminderText r)
+ undefined
main = do
args <- getArgs
if length args == 1 && head args == "--cron"
then doCron
- else if length args == 1 && head args == "--emacs"
+ else if length args == 1 && head args == "--refresh-emacs"
then refreshEmacsEventCache
else maybe
(error "srem: invalid input")
appendUserReminder $ cmdLineReminder args
+
+localHMD :: IO (Hour, Minute, Day)
+localHMD = do
+ localTime <- zonedTimeToLocalTime <$> getZonedTime
+ let time = localTimeOfDay localTime
+ d = localDay localTime
+ h = todHour time
+ m = todMin time
+ return (h, m, d)
diff --git a/src/Types/Reminder.hs b/src/Types/Reminder.hs
index 3c8892c..c0fa8eb 100644
--- a/src/Types/Reminder.hs
+++ b/src/Types/Reminder.hs
@@ -22,6 +22,8 @@
-}
module Types.Reminder ( Reminder
+ , Hour
+ , Minute
, makeReminder
, makeReminder'
, getReminderHour