diff options
| author | Julian Hurst <ark@mansus.space> | 2024-11-15 16:11:37 +0100 |
|---|---|---|
| committer | Julian Hurst <ark@mansus.space> | 2024-11-15 16:11:37 +0100 |
| commit | 0f3c901cb7cdff62dfb87c148bfe136250c117d4 (patch) | |
| tree | 203b61e425117aeb1c401d5e46fd54f12e91b2b0 /distamp.ha | |
| parent | 9637e38657702eda2467eda14ef2e0f06206b2d1 (diff) | |
| parent | ae0a40933be26f24c0fa4bc423d028cb12f91674 (diff) | |
| download | distamp-0f3c901cb7cdff62dfb87c148bfe136250c117d4.tar.gz | |
Merge branch 'timeonly'
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)!; |
