From f483ec5cc73dde773937f604afcd7705afe66192 Mon Sep 17 00:00:00 2001 From: Julian Hurst Date: Thu, 17 Oct 2024 15:35:32 +0200 Subject: Parse the absolute date via a virtual Use a virtual date to parse the user inputted date then fill in the rest of the date information needed to realize the virtual into a real date. --- distamp.ha | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/distamp.ha b/distamp.ha index 215eb07..72a71b1 100644 --- a/distamp.ha +++ b/distamp.ha @@ -76,10 +76,13 @@ fn printdistamp(i: i64) void = { }; fn abs(s: str) (i64 | date::error) = { - // for some reason locality needs to be specified twice (hare stdlib bug?) - const stz = strings::concat(s, " Europe/Paris"); - defer free(stz); - let d = date::from_str("%Y-%m-%d %T %L", stz, chrono::tz("Europe/Paris")!)?; + let v = date::newvirtual(); + v.vloc = chrono::LOCAL; + v.zoff = date::zflag::LAP_EARLY | date::zflag::GAP_END; + date::parse(&v, "%Y-%m-%d %T", s)!; + v.nanosecond = 0; + let d = date::realize(v, chrono::LOCAL)!; + //date::format(os::stderr, "%Y-%m-%d %T %L", &d)!; return time::unix(*(&d: *time::instant)); }; -- cgit v1.2.3