aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2015-04-02 21:51:09 +0900
committerSean Whitton <spwhitton@spwhitton.name>2015-04-02 21:51:09 +0900
commit821539f275da71d60da580f15bb886417c630209 (patch)
tree43dfe7d7238efe51b2bc7d9f722a6e363b0f5762
parent72347f047fa37b433d0d05d89176e7f082c7bcd3 (diff)
downloadsrem-821539f275da71d60da580f15bb886417c630209.tar.gz
finish command line reminder parsing
-rw-r--r--src/Main.hs6
-rw-r--r--src/Types/Reminder/CmdLine.hs23
-rw-r--r--src/Utility/CmdLineRem.hs62
3 files changed, 76 insertions, 15 deletions
diff --git a/src/Main.hs b/src/Main.hs
index daf31dd..0fdb194 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -73,9 +73,11 @@ main = do
then doCron
else if length args == 1 && head args == "--refresh-emacs"
then refreshEmacsEventCache
- else maybe
+ else do
+ maybeParse <- cmdLineReminder args
+ maybe
(error "srem: invalid input")
- appendUserReminder $ cmdLineReminder args
+ appendUserReminder maybeParse
localHMD :: IO (Hour, Minute, Day)
localHMD = do
diff --git a/src/Types/Reminder/CmdLine.hs b/src/Types/Reminder/CmdLine.hs
index b9a311c..4a5f9c2 100644
--- a/src/Types/Reminder/CmdLine.hs
+++ b/src/Types/Reminder/CmdLine.hs
@@ -1,5 +1,28 @@
module Types.Reminder.CmdLine where
+{-
+
+ srem --- Timed reminders as notifications
+
+ Copyright (C) 2015 Sean Whitton
+
+ This file is part of srem.
+
+ srem is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ srem is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with srem. If not, see <http://www.gnu.org/licenses/>.
+
+-}
+
import Text.Regex.Posix ((=~))
data CmdLineRemType = RelativeCLRem | AbsoluteCLRem
diff --git a/src/Utility/CmdLineRem.hs b/src/Utility/CmdLineRem.hs
index 946c14d..46d6340 100644
--- a/src/Utility/CmdLineRem.hs
+++ b/src/Utility/CmdLineRem.hs
@@ -1,24 +1,50 @@
-module Utility.CmdLineRem (cmdLineReminder) where
+{-# LANGUAGE DataKinds #-}
+{-# LANGUAGE TypeOperators #-}
-import Types.Reminder.CmdLine
+{-
+
+ srem --- Timed reminders as notifications
+
+ Copyright (C) 2015 Sean Whitton
+
+ This file is part of srem.
+
+ srem is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ srem is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with srem. If not, see <http://www.gnu.org/licenses/>.
+
+-}
+
+module Utility.CmdLineRem (cmdLineReminder) where
-import Data.List (intercalate)
import Control.Applicative ((<$>))
+import Data.List (intercalate)
-import Data.Tuple.Sequence (sequenceT)
-import System.Locale (defaultTimeLocale)
import Data.List.Split (oneOf, split)
+import Data.Modular
import Data.Time.Calendar
import Data.Time.Format
import Data.Time.LocalTime
+import Data.Tuple.Sequence (sequenceT)
+import System.Locale (defaultTimeLocale)
-import Types.Reminder
import Data.Maybe.Read
+import Types.Reminder
+import Types.Reminder.CmdLine
cmdLineReminder :: [String] -> IO (Maybe Reminder)
cmdLineReminder [] = return Nothing
cmdLineReminder [_] = return Nothing
-cmdLineReminder input@(exp:textParts) =
+cmdLineReminder input@(exp:_) =
case cmdLineRemType exp of
Just AbsoluteCLRem ->
return $ parseAbsoluteRem input
@@ -27,14 +53,24 @@ cmdLineReminder input@(exp:textParts) =
return $ parseRelativeRem tod input
Nothing ->
return Nothing
- where
- text = intercalate " " textParts
-parseRelativeRem :: TimeOfDay -> [String] -> Maybe Reminder
-parseRelativeRem = undefined
+parseRelativeRem :: TimeOfDay -> [String] -> Maybe Reminder
+parseRelativeRem tod (exp:textParts) = do
+ (h, m) <- parseRelativeTime exp
+ let nowH = todHour tod
+ nowM = todMin tod
+ h' = nowH + h + ((nowM + m) `div` 60)
+ m' = unMod $ (toMod nowM :: Int/60) + (toMod m :: Int/60)
+ makeReminder h' m' text
+ where
+ text = intercalate " " textParts
-parseAbsoluteRem :: [String] -> Maybe Reminder
-parseAbsoluteRem = undefined
+parseAbsoluteRem :: [String] -> Maybe Reminder
+parseAbsoluteRem (exp:textParts) = do
+ (h, m) <- parseAbsoluteTime exp
+ makeReminder h m text
+ where
+ text = intercalate " " textParts
parseRelativeTime :: String -> Maybe (Hour, Minute)
parseRelativeTime exp =