hare

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

commit 300318306d5fa06063a0b0621fe9cb505c6f3e85
parent 59c4862afd51dc9b4fccdd142f2777247260d455
Author: Byron Torres <b@torresjrjr.com>
Date:   Wed,  5 Jan 2022 15:15:38 +0000

export timezone pointers

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

Diffstat:
Mdatetime/datetime.ha | 6+++---
Mtime/chrono/timezone.ha | 21++++++++++++++-------
2 files changed, 17 insertions(+), 10 deletions(-)

diff --git a/datetime/datetime.ha b/datetime/datetime.ha @@ -32,7 +32,7 @@ fn init() datetime = datetime { date = 0, time = 0, zone = chrono::zone{ ... }, - loc = &chrono::local, + loc = chrono::local, era = void, year = void, @@ -70,7 +70,7 @@ export fn new( date = calc_epochal_from_ymd(year, month, day)?, time = calc_time_from_hmsn(hour, min, sec, nsec)?, zone = chrono::zone{ zoffset = zoffset, ... }, - loc = if (loc is void) &chrono::local else loc: *chrono::timezone, + loc = if (loc is void) chrono::local else loc: *chrono::timezone, era = void, year = year, @@ -103,7 +103,7 @@ export fn now() datetime = { // /etc/localtime or $TZ? How to determine the system's // timescale? Assuming UTC may be sufficient. zone = chrono::zone{ ... }, - loc = &chrono::local, + loc = chrono::local, era = void, year = void, diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -51,13 +51,14 @@ type tzname = struct { dst_endtime: str, }; -@init set_local_timezone() void { - // TODO - // set time::chrono::local to a correct timezone +// The system's local timezone, set during initialisation +export const local: *timezone = &TZ_local; + +// TODO: set time::chrono::local to a correct timezone +@init fn set_local_timezone() void = { return; }; - -export const local: timezone = timezone { +const TZ_local: timezone = timezone { scale = &UTC, zones = [ zone { @@ -71,7 +72,10 @@ export const local: timezone = timezone { name = "", }; -export const UTC0: timezone = timezone { +// The UTC "Zulu" timezone +export const UTC_Z: *timezone = &TZ_UTC; + +const TZ_UTC: timezone = timezone { scale = &UTC, zones = [ zone { @@ -85,7 +89,10 @@ export const UTC0: timezone = timezone { name = "Etc/UTC", }; -export const TAI0: timezone = timezone { +// The TAI "Zulu" timezone +export const TAI_Z: *timezone = &TZ_TAI; + +const TZ_TAI: timezone = timezone { scale = &TAI, zones = [ zone {