diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2024-12-05 16:12:43 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2024-12-05 16:19:58 +0100 |
| commit | ee5a390445db5af3635bd4c797aed86222f82e80 (patch) | |
| tree | 33073a5f0bf0f8e07bb3957c242d2f8924b8fe94 /hatask.ha | |
| parent | 588f130988c6310f7379be9db6e5a81112653482 (diff) | |
| download | hatask-ee5a390445db5af3635bd4c797aed86222f82e80.tar.gz | |
Support sorting by last modification date
Diffstat (limited to 'hatask.ha')
| -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 => |
