hare

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

commit e6d40f6da1fe80c50816825d20e546c8198296d9
parent c6510afaf6e2cebebc6486f833235a17a4359a6b
Author: Byron Torres <b@torresjrjr.com>
Date:   Mon, 10 Jan 2022 10:17:38 +0000

fix localize(); new fixedzone()

Signed-off-by: Byron Torres <b@torresjrjr.com>

Diffstat:
Mtime/chrono/timezone.ha | 37+++++++++++++++++++++++++++++++++----
1 file changed, 33 insertions(+), 4 deletions(-)

diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -67,9 +67,16 @@ export fn in(loc: locality, m: moment) moment = { // locality. Its .date & .time fields are adjusted by its current zone's offset. export fn localize(m: moment) moment = { const zone = lookupzone(&m); - const newtime = m.time + zone.zoffset; - m.time = newtime % m.loc.daylength; - m.date += (newtime / m.loc.daylength); + const daylen = m.loc.daylength; + + const tnew = m.time + zone.zoffset; + const t = (if (tnew >= 0) tnew else tnew + daylen) % daylen; + + const dnew = (tnew / daylen): int; + const d = m.date + (if (tnew >= 0) dnew else dnew - 1); + + m.time = t; + m.date = d; return m; }; @@ -95,7 +102,29 @@ export fn lookupzone(m: *moment) zone = { m.zone = z; return z; }; - return zone{ ... }; + + abort("TODO"); +}; + +// Creates a [[timezone]] with a single [[zone]], useful for fixed offsets +// +// let hawaii = chrono::fixedzone(&chrono::UTC, chrono::EARTH_DAY, +// chrono::zone { +// zoffset = -10 * time::HOUR, +// name = "Hawaiian Reef", +// abbrev = "HARE", +// dst = false, +// }, +// ); +// +export fn fixedzone(ts: *timescale, daylen: time::duration, z: zone) timezone = { + return timezone { + name = z.name, + timescale = ts, + daylength = daylen, + zones = alloc([z]), + transitions = [], + }; }; // The system's local timezone, set during initialisation