hare

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

commit 67689bec48d2543fe209b956a594922358025883
parent 9dbf69f0bf72d183e20c1e98c68b3ac74f3e50cd
Author: Byron Torres <b@torresjrjr.com>
Date:   Sun,  9 Jan 2022 03:48:01 +0000

expand olsen::tz() with dummy timezones

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

Diffstat:
Mdatetime/timezone.ha | 28----------------------------
Mtime/chrono/timezone.ha | 12++++++------
Mtime/olsen/olsen.ha | 73+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
3 files changed, 77 insertions(+), 36 deletions(-)

diff --git a/datetime/timezone.ha b/datetime/timezone.ha @@ -3,36 +3,8 @@ use time::chrono; // Transforms and creates a new [[datetime]] in a different [[chrono::locality]] export fn in(loc: chrono::locality, dt: datetime) datetime = { - // TODO const old = to_moment(dt); const new = chrono::in(loc, old); const new_dt = from_moment(new); return new_dt; }; - - -// -// Some example timezones -// - -// "CET", "Central European Time" timezone -export const TZ_CET: chrono::timezone = chrono::timezone { - name = "CET", - timescale = &chrono::UTC, - daylength = chrono::EARTH_DAY, - zones = [ - chrono::zone { - zoffset = 1 * time::HOUR, - name = "Central European Time", - abbrev = "CET", - dst = false, - }, - chrono::zone { - zoffset = 2 * time::HOUR, - name = "Central European Summer Time", - abbrev = "CEST", - dst = true, - }, - ], - transitions = [], -}; diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha @@ -79,14 +79,14 @@ export fn lookupzone(m: moment) zone = { }; // The system's local timezone, set during initialisation -export const local: *timezone = &TZ_local; +export const local: locality = &TZ_local; // TODO: set time::chrono::local to a correct timezone @init fn set_local_timezone() void = { return; }; const TZ_local: timezone = timezone { - name = "", + name = "Local", timescale = &UTC, daylength = EARTH_DAY, zones = [ @@ -101,10 +101,10 @@ const TZ_local: timezone = timezone { }; // The UTC (Coordinated Universal Time) "Zulu" timezone -export const UTC_Z: *timezone = &TZ_UTC; +export const UTC_Z: locality = &TZ_UTC; const TZ_UTC: timezone = timezone { - name = "Etc/UTC", + name = "UTC", timescale = &UTC, daylength = EARTH_DAY, zones = [ @@ -119,7 +119,7 @@ const TZ_UTC: timezone = timezone { }; // The TAI (International Atomic Time) "Zulu" timezone -export const TAI_Z: *timezone = &TZ_TAI; +export const TAI_Z: locality = &TZ_TAI; const TZ_TAI: timezone = timezone { name = "", @@ -137,7 +137,7 @@ const TZ_TAI: timezone = timezone { }; // The MTC (Coordinated Martian Time) "Zulu" timezone -export const MTC_Z: *timezone = &TZ_MTC; +export const MTC_Z: locality = &TZ_MTC; const TZ_MTC: timezone = timezone { name = "", diff --git a/time/olsen/olsen.ha b/time/olsen/olsen.ha @@ -2,7 +2,76 @@ use time; use time::chrono; use datetime; -fn tz(id: str) *chrono::timezone = { - // TODO: retrieve timezone from system zoneinfo database +// Parses and retrieves a [[chrono::timezone]] from the system zoneinfo +// database, or if applicable, from an internal selection of timezones. +export fn tz(id: str) chrono::locality = { + switch (id) { + case "Local" => + return chrono::local; + case "UTC" => + return chrono::UTC_Z; + case "TAI" => + return chrono::TAI_Z; + case "MTC" => + return chrono::MTC_Z; + case => + void; + }; + + // TODO: temporary + if (id == "Europe/Amsterdam") { + return TZ_Europe__Amsterdam; + }; + return chrono::local; }; + +// TODO: Here are some temporary timezones until a full parser is written + +// Europe/Amsterdam timezone +export const TZ_Europe__Amsterdam: chrono::locality = &tz_europe__amsterdam; + +const tz_europe__amsterdam: chrono::timezone = chrono::timezone{ + name = "Europe/Amsterdam", + timescale = &chrono::UTC, + daylength = chrono::EARTH_DAY, + zones = [ + chrono::zone { + zoffset = 1 * time::HOUR, + name = "Central European Time", + abbrev = "CET", + dst = false, + }, + chrono::zone { + zoffset = 2 * time::HOUR, + name = "Central European Summer Time", + abbrev = "CEST", + dst = true, + }, + ], + transitions = [], +}; + +// CET (Central European Time) timezone +export const TZ_CET: chrono::locality = &tz_cet; + +const tz_cet: chrono::timezone = chrono::timezone{ + name = "CET", + timescale = &chrono::UTC, + daylength = chrono::EARTH_DAY, + zones = [ + chrono::zone { + zoffset = 1 * time::HOUR, + name = "Central European Time", + abbrev = "CET", + dst = false, + }, + chrono::zone { + zoffset = 2 * time::HOUR, + name = "Central European Summer Time", + abbrev = "CEST", + dst = true, + }, + ], + transitions = [], +};