hare

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

commit 15fce5c0093efb02b6de29cca4e9a629aa4c94ad
parent 5edd24a061c20235cbb3c3e26b5c354b0f229db6
Author: Byron Torres <b@torresjrjr.com>
Date:   Mon, 20 Dec 2021 02:12:39 +0000

use zone in datetime

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

Diffstat:
Mdatetime/datetime.ha | 12++++++------
Mtime/chrono/chronology.ha | 6+++---
Mtime/chrono/timezone.ha | 52++++++++++++++++++++++++++++++++--------------------
3 files changed, 41 insertions(+), 29 deletions(-)

diff --git a/datetime/datetime.ha b/datetime/datetime.ha @@ -28,8 +28,8 @@ export type datetime = struct { fn init() datetime = datetime { date = 0, time = 0, - loc = chrono::locality{ ... }, - tz = chrono::local, + zone = chrono::zone{ ... }, + tz = &chrono::local, era = void, year = void, @@ -66,8 +66,8 @@ export fn new( const dt = datetime { date = calc_epochal_from_ymd(year, month, day)?, time = calc_time_from_hmsn(hour, min, sec, nsec)?, - loc = chrono::locality{ zoffset = zoffset, ... }, - tz = if (tz is void) chrono::local else tz: *chrono::timezone, + zone = chrono::zone{ zoffset = zoffset, ... }, + tz = if (tz is void) &chrono::local else tz: *chrono::timezone, era = void, year = year, @@ -100,8 +100,8 @@ export fn now() datetime = { // TODO: What to do here? How to get the timezone from // /etc/localtime or $TZ? How to determine the system's // timescale? Assuming UTC may be sufficient. - loc = chrono::locality{ ... }, - tz = chrono::local, + zone = chrono::zone{ ... }, + tz = &chrono::local, era = void, year = caldate.0, diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha @@ -1,11 +1,11 @@ use time; -// A date & time within a locality, to be contextualised in a chronology +// A date & time, within a locality, intepreted via a chronology export type moment = struct { date: epochal, time: time::duration, - loc: locality, - tz: (*timezone | local), + zone: zone, + tz: *timezone, }; // An ordinal day on earth since the calendar epoch (zeroth day) 1970-01-01 diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -1,26 +1,11 @@ use time; -// The locality of a datetime -export type locality = struct { - zrepr: str, // %Z +// The zoneinfo of a datetime +export type zoneinfo = struct { + zabbrev: str, // %Z zoffset: zoffset, // %z }; -// A destructured dual std/dst POSIX timezone. See tzset(3). -type tzname = struct { - std_name: str, - std_offset: zoffset, - dst_name: str, - dst_offset: zoffset, - dst_start: str, - dst_starttime: str, - dst_end: str, - dst_endtime: str, -}; - -// Represents its associated datetime as local -export type local = void; - // A simple, constant zone offset export type zoffset = time::duration; @@ -46,12 +31,39 @@ export type zonetran = struct { zoneindex: int, }; +// An alias to a timezone export type tzalias = struct { name: str, tz: *timezone, }; -export const TZ_UTC: timezone = timezone { +// A destructured dual std/dst POSIX timezone. See tzset(3). +type tzname = struct { + std_name: str, + std_offset: zoffset, + dst_name: str, + dst_offset: zoffset, + dst_start: str, + dst_starttime: str, + dst_end: str, + dst_endtime: str, +}; + +export const local: timezone = timezone { + scale = &UTC, + zones = [ + zone { + zoffset = 0 * time::SECOND, + name = "Local Time", + abbrev = "", + dst = false, + }, + ], + trans = [], + name = "", +}; + +export const UTC0: timezone = timezone { scale = &UTC, zones = [ zone { @@ -65,7 +77,7 @@ export const TZ_UTC: timezone = timezone { name = "Etc/UTC", }; -export const TZ_TAI: timezone = timezone { +export const TAI0: timezone = timezone { scale = &TAI, zones = [ zone {