diff options
| author | Julian Hurst <julian.hurst@digdash.com> | 2024-11-12 17:06:30 +0100 |
|---|---|---|
| committer | Julian Hurst <julian.hurst@digdash.com> | 2024-11-12 17:08:15 +0100 |
| commit | ae0a40933be26f24c0fa4bc423d028cb12f91674 (patch) | |
| tree | 6eab426bcf33ce3fb76858c435136e0ff1c2f44c /distamp.ha | |
| parent | 87254486a840b4d557f3fb6673c3f8c3073f8521 (diff) | |
| download | distamp-ae0a40933be26f24c0fa4bc423d028cb12f91674.tar.gz | |
abs: Support a fallback to parsing only time using current date
When -a flag is used parse first "%F %T", on error fallback to "%T"
using the "%F" format date of the localnow date.
Diffstat (limited to 'distamp.ha')
| -rw-r--r-- | distamp.ha | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -3,9 +3,12 @@ use time; use time::date; use time::chrono; use os; +use io; use strconv; use strings; use getopt; +use memio; +use encoding::utf8; type parseerror = !strconv::error; @@ -97,11 +100,21 @@ fn printdistamp(i: i64) void = { fmt::printfln("<t:{}:R>", i)!; }; -fn abs(conf: config, s: str) (i64 | date::error) = { +fn abs(conf: config, s: str) (i64 | date::error | io::error | utf8::invalid) = { let v = date::newvirtual(); v.vloc = conf.tz; v.zoff = date::zflag::LAP_EARLY | date::zflag::GAP_END; - date::parse(&v, "%Y-%m-%d %T", s)?; + match (date::parse(&v, "%Y-%m-%d %T", s)) { + case date::parsefail => + const now = date::localnow(); + const buf: [10]u8 = [0...]; + const st = memio::fixed(buf); + date::format(&st, "%F", &now)?; + date::parse(&v, "%F", memio::string(&st)?)?; + date::parse(&v, "%T", s)?; + case void => + void; + }; v.nanosecond = 0; let d = date::realize(v, chrono::LOCAL)?; //date::format(os::stderr, "%Y-%m-%d %T %L", &d)!; |
