From daf372c98d4a9df43c8270bdf9b414e9820aea90 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Wed, 30 Oct 2024 18:21:05 +0100 Subject: Add config support for specifying a timezone --- distamp.ha | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'distamp.ha') diff --git a/distamp.ha b/distamp.ha index be2ce02..0b908ed 100644 --- a/distamp.ha +++ b/distamp.ha @@ -19,17 +19,22 @@ export fn main() void = { ); defer getopt::finish(&cmd); + const conf = match (loadconfig()) { + case let e: conferror => + fmt::fatal(strconferror(e)); + case let c: config => + yield c; + }; + let days: time::duration = 0; let weeks: time::duration = 0; for (let opt .. cmd.opts) { switch (opt.0) { case 'a' => - match (abs(opt.1)) { + match (abs(conf, opt.1)) { case let i: i64 => printdistamp(i); return; - case let e: chrono::tzdberror => - fmt::fatal(chrono::strerror(e)); case let e: date::parsefail => let s = strings::concat(date::strerror(e), "\n", "Date format must be 'year-month-day hour:minute:second'"); defer free(s); @@ -77,9 +82,10 @@ fn printdistamp(i: i64) void = { fmt::printfln("", i)!; }; -fn abs(s: str) (i64 | date::error | chrono::tzdberror) = { +fn abs(conf: config, s: str) (i64 | date::error) = { let v = date::newvirtual(); - v.vloc = chrono::tz("Europe/Paris")?; + v.vloc = conf.tz; + //v.vloc = chrono::tz("Europe/Paris")?; v.zoff = date::zflag::LAP_EARLY | date::zflag::GAP_END; date::parse(&v, "%Y-%m-%d %T", s)?; v.nanosecond = 0; -- cgit v1.2.3