about summary refs log tree commit diff
path: root/notyet
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2019-08-15 19:09:55 +0200
committerLeah Neukirchen <leah@vuxu.org>2019-08-15 19:09:55 +0200
commit163069ef871e57beb44c324bc166d2991b752ceb (patch)
treeedf72cfc45e83ff657c53f2c2b4a9dc0ca14c50e /notyet
parent29532bc4814051a842df34c05aa74b18dcfd5dea (diff)
downloadnotyet-163069ef871e57beb44c324bc166d2991b752ceb.tar.gz
notyet-163069ef871e57beb44c324bc166d2991b752ceb.tar.xz
notyet-163069ef871e57beb44c324bc166d2991b752ceb.zip
add time stamp markers (+/-/!), inspired from howm
Diffstat (limited to 'notyet')
-rwxr-xr-xnotyet25
1 files changed, 24 insertions, 1 deletions
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