aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2015-03-29 17:19:36 +0900
committerSean Whitton <spwhitton@spwhitton.name>2015-03-29 17:19:36 +0900
commit1e95f1f7c799f4b63b554fc181aed49f0737d8c7 (patch)
tree6169766db0035a06e1e0dbafc136cca10444edd3
parent007c2c303d727727f1755ac7911fe995fad098e0 (diff)
downloadsrem-1e95f1f7c799f4b63b554fc181aed49f0737d8c7.tar.gz
implement staggering of reminders drawn from Emacs
-rw-r--r--src/Control/SremConfig.hs4
-rw-r--r--src/Utility/Emacs.hs26
-rw-r--r--srem.cabal1
3 files changed, 18 insertions, 13 deletions
diff --git a/src/Control/SremConfig.hs b/src/Control/SremConfig.hs
new file mode 100644
index 0000000..ef62cbe
--- /dev/null
+++ b/src/Control/SremConfig.hs
@@ -0,0 +1,4 @@
+module Control.SremConfig where
+
+intervals :: [Int]
+intervals = [60, 15, 0]
diff --git a/src/Utility/Emacs.hs b/src/Utility/Emacs.hs
index 27f0830..7ea7639 100644
--- a/src/Utility/Emacs.hs
+++ b/src/Utility/Emacs.hs
@@ -1,13 +1,17 @@
+{-# LANGUAGE DataKinds, TypeOperators #-}
+
module Utility.Emacs ( getEmacsOutput
, parseEmacsOutput) where
import Control.Applicative ((<$>))
-import Control.Monad (when, foldM)
+import Control.Monad (foldM, when)
+import qualified Control.SremConfig as SremConfig
import Data.Maybe.Read
import System.Directory (getHomeDirectory)
import System.Process (readProcess)
import Text.Regex.Posix ((=~))
import Types.Reminder
+import Data.Modular
parseEmacsOutput :: String -> [Reminder]
parseEmacsOutput = foldr step [] . drop 2 . lines
@@ -29,18 +33,14 @@ parseLine line = do
lineMatchStrings = line =~ apptRegexp :: [[String]]
staggeredReminders :: Reminder -> Maybe [Reminder]
-staggeredReminders r = undefined
-
--- staggeredReminders :: Int -> Int -> String -> [Reminder]
--- staggeredReminders hour mins text = foldl' step [] [60, 15, 0]
--- where step rems diff = let hour'
--- | diff > mins = hour - 1
--- | otherwise = hour
--- -- could do with addition mod 60
--- mins'
--- | mins >= diff = mins - diff
--- | otherwise = 60 + (mins - diff)
--- in rems ++ [Reminder hour' mins' text]
+staggeredReminders r = sequence $ foldr step [] SremConfig.intervals
+ where
+ step minsBefore rems =
+ makeReminder (h minsBefore) (m minsBefore) (getReminderText r) : rems
+ h m = if m > getReminderMinute r
+ then getReminderHour r - 1
+ else getReminderHour r
+ m m = unMod $ (toMod (getReminderMinute r) :: Int/60) - (toMod m :: Int/60)
getEmacsOutput :: IO String
getEmacsOutput = do
diff --git a/srem.cabal b/srem.cabal
index dfc7d87..ad94ce0 100644
--- a/srem.cabal
+++ b/srem.cabal
@@ -16,5 +16,6 @@ executable srem
, directory
, process
, regex-posix
+ , modular-arithmetic
hs-source-dirs: src
default-language: Haskell2010