diff options
author | Leah Neukirchen <leah@vuxu.org> | 2017-10-02 15:33:02 +0200 |
---|---|---|
committer | Leah Neukirchen <leah@vuxu.org> | 2017-10-02 15:33:02 +0200 |
commit | c1a23ce5345c95c1d374325c8f5e4dc0182602de (patch) | |
tree | f3062374c7d9eb3ef00dad3b582dcc6fab9aa52f | |
parent | ac55862e8080b26bef20acf4b798ef3d00a8da90 (diff) | |
download | notyet-c1a23ce5345c95c1d374325c8f5e4dc0182602de.tar.gz notyet-c1a23ce5345c95c1d374325c8f5e4dc0182602de.tar.xz notyet-c1a23ce5345c95c1d374325c8f5e4dc0182602de.zip |
compute days remaining for all dates
-rwxr-xr-x | notyet | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/notyet b/notyet index ce2366f..ea778e4 100755 --- a/notyet +++ b/notyet @@ -7,6 +7,7 @@ # http://creativecommons.org/publicdomain/zero/1.0/ require 'date' +TODAY = Date.today class Entry < Struct.new(:depth, :state, :desc, :file, :line, :children) def reindent(change) @@ -62,13 +63,18 @@ class Entry < Struct.new(:depth, :state, :desc, :file, :line, :children) force("?") end - soonest = children.map { |c| - "-?".index(c.state) && - c.desc[/^(?:\(.*?\)\s*)?(\d\d\d\d-\d\d-\d\d)/, 1] - }.compact.min - if soonest - diff = "%+d" % (Date.parse(soonest) - Date.today) - self.desc = "#{soonest} {#{diff}} #{desc}" + if desc =~ /^(?:\(.*?\)\s*)?(\d\d\d\d-\d\d-\d\d)/ + diff = "%+d" % (Date.parse($1) - TODAY) + self.desc = "#{$1} {#{diff}}#{$'}" + else + soonest = children.map { |c| + "-?".index(c.state) && + c.desc[/^(?:\(.*?\)\s*)?(\d\d\d\d-\d\d-\d\d)/, 1] + }.compact.min + if soonest + diff = "%+d" % (Date.parse(soonest) - TODAY) + self.desc = "#{soonest} {#{diff}} #{desc}" + end end end end |