Add `$now` variable to get the current date
authorMarkus Hauck <markus1189@gmail.com>
Tue, 21 Nov 2017 19:35:02 +0000 (19:35 +0000)
committerMarkus Hauck <markus1189@gmail.com>
Tue, 21 Nov 2017 19:35:02 +0000 (19:35 +0000)
fixes: #6

categorize.cfg
doc/arbtt.xml
src/Categorize.hs

index d45d668..d695d56 100644 (file)
@@ -125,4 +125,9 @@ format $date =~ ".*-03-19"  ==> tag period:on_a_special_day,
 month $date == 1 ==> tag month:January,
 month $date == 2 ==> tag month:February,
 year $date == 2010 ==> tag year:2010,
+
+-- “$now” evaluates to the current time
+day of month $now == day of month $date ==> tag current-day,
+month $now == month $date ==> tag current-month,
+year $now == year $date ==> tag current-year,
 -}
index 16d3c76..01b974d 100644 (file)
@@ -432,7 +432,7 @@ $ runhaskell Setup.hs install</screen>
       <production id="g-date">
         <lhs>Date</lhs>
         <rhs> <quote>$date</quote> </rhs>
-        <!-- <rhs> <quote>$now</quote> </rhs> -->
+        <rhs> <quote>$now</quote> </rhs>
       </production>
 
       <production id="g-timediff">
index 8395ed2..565ecc0 100644 (file)
@@ -381,6 +381,8 @@ parseCondPrim = choice
                            return $ CondTime (getTimeVar "sampleage")
                       , do guard $ varname == "date"
                            return $ CondDate (getDateVar "date")
+                      , do guard $ varname == "now"
+                           return $ CondDate (getDateVar "now")
                       , do guard $ varname == "desktop"
                            return $ CondString (getVar "desktop")
                      ]
@@ -546,7 +548,8 @@ getTimeVar "time" ctx = Just $
 getTimeVar "sampleage" ctx = Just $ cCurrentTime ctx `diffUTCTime` tlTime (cNow ctx)
 
 getDateVar :: String -> CtxFun UTCTime
-getDateVar "date" ctx = Just $ tlTime (cNow ctx)
+getDateVar "date" = Just . tlTime . cNow
+getDateVar "now" = Just . cCurrentTime
 
 findActive :: [(Bool, t, t1)] -> Maybe (Bool, t, t1)
 findActive = find (\(a,_,_) -> a)