hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 692ae2dad8c233f26790125712528c69fe954921
parent 95933b0482f4b61613ff3b21878c4d65c09b9f31
Author: Byron Torres <b@torresjrjr.com>
Date:   Mon, 25 Mar 2024 02:17:02 +0000

time::date: realize: require .vloc, no UTC default

Breaking-change: 0.24.1

Diffstat:
Mencoding/asn1/decoder.ha | 2++
Mtime/date/date.ha | 3+++
Mtime/date/error.ha | 2++
Mtime/date/virtual.ha | 13+++++++------
4 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/encoding/asn1/decoder.ha b/encoding/asn1/decoder.ha @@ -8,6 +8,7 @@ use io; use math::{bit_size_u8}; use os; use strings; +use time::chrono; use time::date; use types; @@ -700,6 +701,7 @@ export fn read_utctime(d: *decoder, maxyear: u16) (date::date | error) = { }; let v = date::newvirtual(); + v.vloc = chrono::UTC; v.year = (year + cent): int; v.zoff = 0; v.nanosecond = 0; diff --git a/time/date/date.ha b/time/date/date.ha @@ -244,6 +244,9 @@ export fn from_str( v.second = 0; v.nanosecond = 0; parse(&v, layout, s)?; + if (v.locname is void || len(locs) == 0) { + v.vloc = chrono::UTC; + }; return realize(v, locs...)?; }; diff --git a/time/date/error.ha b/time/date/error.ha @@ -15,6 +15,8 @@ export fn strerror(err: error) const str = { static let buf: [92]u8 = [0...]; return strings::rtrim(fmt::bsprint(buf, "Insufficient date information, could not calculate:", + if (lack & insufficient::LOCALITY: u8 == 0) "" else + "locality", if (lack & insufficient::DAYDATE: u8 == 0) "" else "daydate", if (lack & insufficient::DAYTIME: u8 == 0) "" else diff --git a/time/date/virtual.ha b/time/date/virtual.ha @@ -9,9 +9,10 @@ use time::chrono; export type insufficient = !lack; // TODO: drop alias workaround export type lack = enum u8 { - DAYDATE = 1 << 0, // could not infer daydate - DAYTIME = 1 << 1, // could not infer time-of-day - ZOFF = 1 << 2, // could not infer zone offset + LOCALITY = 1 << 0, // could not deduce locality + DAYDATE = 1 << 1, // could not deduce daydate + DAYTIME = 1 << 2, // could not deduce time-of-day + ZOFF = 1 << 3, // could not deduce zone offset }; // A virtual date; a [[date]] wrapper interface, which represents a date of @@ -130,7 +131,6 @@ export fn newvirtual() virtual = virtual { // - .locname : This is compared to the .name field of each locality // provided via the locs parameter, or "UTC" if none are provided. // The first matching locality is used. -// - (nothing) : Defaults to [[time::chrono::UTC]]. // // The instant ([[time::instant]]) value depends on: // @@ -164,17 +164,18 @@ export fn realize( ) (date | insufficient | invalid) = { let lacking = 0u8; - // determine .loc (defaults to time::chrono::UTC) + // determine .loc if (v.vloc is chrono::locality) { v.loc = v.vloc as chrono::locality; } else if (v.locname is str) { - v.loc = chrono::UTC; for (let loc .. locs) { if (loc.name == v.locname as str) { v.loc = loc; break; }; }; + } else { + lacking |= insufficient::LOCALITY; }; // try using .vsec .vnsec