hare

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

commit 9dbf69f0bf72d183e20c1e98c68b3ac74f3e50cd
parent f9c6d44f3f1192e767cc51c71c72a43226df7351
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun,  9 Jan 2022 03:05:47 +0000

new timezone in() functions

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

Diffstat:
Mdatetime/timezone.ha | 9++++++---
Mtime/chrono/timezone.ha | 8++++++--
2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/datetime/timezone.ha b/datetime/timezone.ha @@ -1,10 +1,13 @@ use time; use time::chrono; -// Retrieves a IANA timezone object by name -export fn tzdb(name: str) chrono::timezone = { +// Transforms and creates a new [[datetime]] in a different [[chrono::locality]] +export fn in(loc: chrono::locality, dt: datetime) datetime = { // TODO - return chrono::timezone { ... }; + const old = to_moment(dt); + const new = chrono::in(loc, old); + const new_dt = from_moment(new); + return new_dt; }; diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -58,9 +58,13 @@ type tzname = struct { dst_endtime: str, }; +// Transforms and creates a new [[moment]] in a different [[locality]] +export fn in(loc: locality, m: moment) moment = { + return new(m.date, m.time, m.loc); // resets .zone +}; + // Returns a fictitious moment which assumes it's own locality is the normal -// locality. The given timezone is consulted to find the current zone, and its -// offset is applied to the new .date and .time fields. +// 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;