diff options
| -rw-r--r-- | hatask.ha | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -14,6 +14,7 @@ use getopt; use sort; use fnmatch; use errors; +use time; type task = struct { name: str, @@ -22,6 +23,7 @@ type task = struct { tags: []str, priority: uint, content: str, + lmd: time::instant, }; def METADATASEP: str = "----"; @@ -76,9 +78,12 @@ fn readtask(taskpath: str) (task | rtaskerror) = { io::seek(&meta, 0, io::whence::SET)?; const isc = ini::scan(&meta); defer ini::finish(&isc); + + const stat = os::stat(taskpath)?; let t = task { context = void, tags = [], + lmd = stat.mtime, ... }; for (let entry: ini::entry => ini::next(&isc)?) { @@ -129,6 +134,12 @@ fn sortname(a: const *opaque, b: const *opaque) int = { return strings::compare(a.name, b.name); }; +fn sortlmd(a: const *opaque, b: const *opaque) int = { + const a = a: *task; + const b = b: *task; + return time::compare(b.lmd, a.lmd); +}; + fn strrtaskerror(e: rtaskerror) str = { return match (e) { case let e: fs::error => @@ -176,6 +187,7 @@ export fn main() void = { ('c', "context", "context filter"), ('t', "tags", "tags filter"), ('p', "sort by priority"), + ('m', "sort by last modification date"), ('d', "activate debug mode"), ("filter", ["filter tasks", "id"]: []getopt::help), ("f", ["filter tasks", "id"]: []getopt::help), @@ -218,6 +230,8 @@ export fn main() void = { cfg.tags = strings::dupall(strings::split(opt.1, ",")); case 'p' => sortfn = &sortpriority; + case 'm' => + sortfn = &sortlmd; case 'd' => cfg.debug = true; case => |
