diff options
| -rw-r--r-- | distamp.ha | 32 |
1 files changed, 25 insertions, 7 deletions
@@ -4,6 +4,8 @@ use os; use strconv; use strings; +type parseerror = strconv::error; + export fn main() void = { if (len(os::args) != 2) { os::exit(os::status::FAILURE); @@ -16,16 +18,32 @@ export fn main() void = { let li = if (len(spl) > 2) { fmt::fatal("Duration format: m or m:s"); - } else if (len(spl) == 2) { - let m = strconv::stoi64(spl[0])!; - let s = strconv::stoi64(spl[1])!; + } else { + yield match (parsetime(i, spl)) { + case let inst: time::instant => + yield inst; + case let e: parseerror => + fmt::fatal(strerror(e)); + }; + }; + + fmt::printfln("<t:{}:R>", time::unix(li))!; +}; + +fn strerror(e: parseerror) str = { + return strconv::strerror(e); +}; + +fn parsetime(clk: time::instant, spl: []str) (time::instant | parseerror) = { + return if (len(spl) == 2) { + let m = strconv::stoi64(spl[0])?; + let s = strconv::stoi64(spl[1])?; let d = (m * time::MINUTE) + (s * time::SECOND); - yield time::add(i, d); + yield time::add(clk, d); } else { - let m = strconv::stoi64(spl[0])!; + let m = strconv::stoi64(spl[0])?; let d = m * time::MINUTE; - yield time::add(i, d); + yield time::add(clk, d); }; - fmt::printfln("<t:{}:R>", time::unix(li))!; }; |
