about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--README.md7
-rwxr-xr-xnotyet25
2 files changed, 31 insertions, 1 deletions
diff --git a/README.md b/README.md
index a522577..eb69ed7 100644
--- a/README.md
+++ b/README.md
@@ -32,6 +32,13 @@ I recommend using two spaces for each level.
 
 Additionally, a task can have an assigned date if it starts with the
 ISO format `[YYYY-MM-DD]` or `[YYYY-MM-DD HH:MM]`.
+After such a time stamp, there are three possible markers:
+
+* `+` (or none): a task to be done until this date, priorized by date,
+  i.e. stays on top priority after the date.
+* `-`: a reminder for this date, ordered by *days* to/past the date,
+  i.e. priority sinks after the date.
+* `!`: a task with a hard deadline, with lowest priority after the date.
 
 When you run notyet, it will read the task file (by default `~/.notyet`,
 use `-f` to override) and *aggregate the tasks*:
diff --git a/notyet b/notyet
index c499aba..9723e8e 100755
--- a/notyet
+++ b/notyet
@@ -8,7 +8,10 @@
 
 require 'optionparser'
 require 'date'
+require 'time'
+
 TODAY = Date.today
+NOW = Time.now
 
 class Entry < Struct.new(:depth, :state, :desc, :file, :line, :children)
   def reindent(change)
@@ -49,7 +52,27 @@ class Entry < Struct.new(:depth, :state, :desc, :file, :line, :children)
 
   def sort
     children.each { |c| c.sort }
-    children.sort_by! { |c| [c.state, c.desc] }
+    children.sort_by! { |c| [c.state, c.dateorder, c.desc] }
+  end
+
+  def dateorder
+    if desc =~ /^(?:\(.*?\)\s*)?\[(\d\d\d\d-\d\d-\d\d)( \d\d:\d\d)?\]([+!-]?)/
+      d = Time.parse("#{$1}#{$2}")
+      case $3
+      when "+", ""  # todo (default) = earliest first
+        d - NOW
+      when "-"      # reminder = sort by difference to now
+        (d - NOW).abs
+      when "!"      # deadline, drop after the time
+        if NOW < d
+          d - NOW
+        else
+          Float::INFINITY
+        end
+      end
+    else
+      Float::INFINITY
+    end
   end
 
   def propagate