commit 95a0e5959caecfe41275a7ef84bbbf817c52c20d
parent b7ab838b3bc1a1b468d7444735cacd82175e852e
Author: Byron Torres <b@torresjrjr.com>
Date: Mon, 31 Jan 2022 15:28:36 +0000
rename base timezones and timescales
Signed-off-by: Byron Torres <b@torresjrjr.com>
Diffstat:
5 files changed, 73 insertions(+), 73 deletions(-)
diff --git a/datetime/datetime.ha b/datetime/datetime.ha
@@ -30,7 +30,7 @@ export type datetime = struct {
fn init() datetime = datetime {
date = 0,
time = 0,
- loc = chrono::local,
+ loc = chrono::LOCAL,
zone = chrono::zone { ... },
era = void,
@@ -135,7 +135,7 @@ export fn new(
let m = chrono::new(
calc_epochal_from_ymd(year, month, day)?,
calc_time_from_hmsn(hour, min, sec, nsec)?,
- if (loc is void) chrono::local else loc: *chrono::timezone,
+ if (loc is void) chrono::LOCAL else loc: *chrono::timezone,
);
// figuring out what zone this moment observes
@@ -175,7 +175,7 @@ export fn new(
// TODO: specify appropriate params like a time::clock and chrono::timezone.
export fn now() datetime = {
const i = time::now(time::clock::REALTIME);
- const m = chrono::from_instant(i, chrono::local);
+ const m = chrono::from_instant(i, chrono::LOCAL);
return from_moment(m);
};
diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha
@@ -14,7 +14,7 @@ export type moment = struct {
// TODO: make locality nullable? would make moment "{ ... }" initable
// without a "new" function, though all functions would have to default
// to a particular locality, which might be bad design considering we
- // don't just support UTC_Z.
+ // don't just support UTC.
loc: locality,
// The current [[zone]] this moment observes
@@ -60,7 +60,7 @@ export fn to_instant(m: moment) time::instant = {
};
// The temporal length of a day on Earth.
-// Interpreted with an appropriate timescale like UTC, TAI, GPS.
+// Interpreted with an appropriate timescale like utc, tai, gps.
export def EARTH_DAY: time::duration = 86400 * time::SECOND;
// The following are temporary constants for demonstration of non-terrestrial
diff --git a/time/chrono/timescale.ha b/time/chrono/timescale.ha
@@ -15,7 +15,7 @@ export type ts_converter = fn(i: time::instant) (time::instant | time::error);
//
// The realisation of proper time on Earth's geoid.
// Continuous (no leap seconds).
-export const TAI: timescale = timescale {
+export const tai: timescale = timescale {
name = "International Atomic Time",
abbr = "TAI",
to_tai = &conv_tai_tai,
@@ -38,27 +38,27 @@ fn conv_tai_tai(i: time::instant) (time::instant | time::error) = {
// Used as the basis of civil timekeeping.
// Based on TAI, with an offset, changed roughly biannually.
// Discontinuous (has leap seconds).
-export const UTC: timescale = timescale {
+export const utc: timescale = timescale {
name = "Coordinated Universal Time",
abbr = "UTC",
to_tai = &conv_utc_tai,
from_tai = &conv_tai_utc,
};
-fn conv_tai_utc(tai: time::instant) (time::instant | time::error) = {
- const utc = time::instant {
- sec = tai.sec - 37,
- nsec = tai.nsec,
+fn conv_tai_utc(a: time::instant) (time::instant | time::error) = {
+ const b = time::instant {
+ sec = a.sec - 37,
+ nsec = a.nsec,
};
- return utc;
+ return b;
};
-fn conv_utc_tai(utc: time::instant) (time::instant | time::error) = {
- const tai = time::instant {
- sec = utc.sec + 37,
- nsec = utc.nsec,
+fn conv_utc_tai(a: time::instant) (time::instant | time::error) = {
+ const b = time::instant {
+ sec = a.sec + 37,
+ nsec = a.nsec,
};
- return tai;
+ return b;
};
@@ -67,27 +67,27 @@ fn conv_utc_tai(utc: time::instant) (time::instant | time::error) = {
// Used for computer timekeeping.
// Based on UTC, near 1-to-1 correspondence.
// Discontinuous (has leap seconds).
-export const UNIX: timescale = timescale {
+export const unix: timescale = timescale {
name = "Unix Time",
abbr = "UNIX",
to_tai = &conv_utc_tai,
from_tai = &conv_tai_utc,
};
-fn conv_tai_unix(tai: time::instant) (time::instant | time::error) = {
- const unix = time::instant {
- sec = tai.sec - 37,
- nsec = tai.nsec,
+fn conv_tai_unix(a: time::instant) (time::instant | time::error) = {
+ const b = time::instant {
+ sec = a.sec - 37,
+ nsec = a.nsec,
};
- return unix;
+ return b;
};
-fn conv_unix_tai(unix: time::instant) (time::instant | time::error) = {
- const tai = time::instant {
- sec = unix.sec + 37,
- nsec = unix.nsec,
+fn conv_unix_tai(a: time::instant) (time::instant | time::error) = {
+ const b = time::instant {
+ sec = a.sec + 37,
+ nsec = a.nsec,
};
- return tai;
+ return b;
};
@@ -96,27 +96,27 @@ fn conv_unix_tai(unix: time::instant) (time::instant | time::error) = {
// Used for GPS coordination.
// Based on TAI, constant -19 second offset.
// Continuous (no leap seconds).
-export const GPS: timescale = timescale {
+export const gps: timescale = timescale {
name = "Global Positioning System Time",
abbr = "GPS",
to_tai = &conv_utc_tai,
from_tai = &conv_tai_utc,
};
-fn conv_tai_gps(tai: time::instant) (time::instant | time::error) = {
- const gps = time::instant {
- sec = tai.sec - 19,
- nsec = tai.nsec,
+fn conv_tai_gps(a: time::instant) (time::instant | time::error) = {
+ const b = time::instant {
+ sec = a.sec - 19,
+ nsec = a.nsec,
};
- return gps;
+ return b;
};
-fn conv_gps_tai(gps: time::instant) (time::instant | time::error) = {
- const tai = time::instant {
- sec = gps.sec + 19,
- nsec = gps.nsec,
+fn conv_gps_tai(a: time::instant) (time::instant | time::error) = {
+ const b = time::instant {
+ sec = a.sec + 19,
+ nsec = a.nsec,
};
- return tai;
+ return b;
};
@@ -134,20 +134,20 @@ export const TT: timescale = timescale {
def TT_OFFSET: time::duration = 32.184 * time::SECOND;
-fn conv_tai_tt(tai: time::instant) (time::instant | time::error) = {
+fn conv_tai_tt(a: time::instant) (time::instant | time::error) = {
const tt = time::instant {
- sec = tai.sec + (TT_OFFSET / time::SECOND),
- nsec = tai.nsec + (TT_OFFSET % time::SECOND),
+ sec = a.sec + (TT_OFFSET / time::SECOND),
+ nsec = a.nsec + (TT_OFFSET % time::SECOND),
};
return tt;
};
fn conv_tt_tai(tt: time::instant) (time::instant | time::error) = {
- const tai = time::instant {
+ const b = time::instant {
sec = tt.sec - (TT_OFFSET / time::SECOND),
nsec = tt.nsec + (TT_OFFSET % time::SECOND),
};
- return tai;
+ return b;
};
@@ -162,7 +162,7 @@ fn conv_tt_tai(tt: time::instant) (time::instant | time::error) = {
// Used for local solar time on Mars.
// Based on TT, with a constant factor.
// Continuous (no leap seconds).
-export const MTC: timescale = timescale {
+export const mtc: timescale = timescale {
name = "Coordinated Mars Time",
abbr = "MTC",
to_tai = &conv_mtc_tai,
@@ -171,22 +171,22 @@ export const MTC: timescale = timescale {
def FACTOR_TERRESTRIAL_MARTIAN: f64 = 1.0274912517;
-fn conv_tai_mtc(tai: time::instant) (time::instant | time::error) = {
+fn conv_tai_mtc(a: time::instant) (time::instant | time::error) = {
// TODO: handle propagated ambiguous errors
- const tt = TT.from_tai(tai)?;
- const mtc = time::instant {
+ const tt = TT.from_tai(a)?;
+ const b = time::instant {
sec = (tt.sec: f64 * FACTOR_TERRESTRIAL_MARTIAN): i64,
nsec = tt.nsec,
};
- return mtc;
+ return b;
};
-fn conv_mtc_tai(mtc: time::instant) (time::instant | time::error) = {
+fn conv_mtc_tai(a: time::instant) (time::instant | time::error) = {
const tt = time::instant {
- sec = (mtc.sec: f64 / FACTOR_TERRESTRIAL_MARTIAN): i64,
- nsec = mtc.nsec,
+ sec = (a.sec: f64 / FACTOR_TERRESTRIAL_MARTIAN): i64,
+ nsec = a.nsec,
};
// TODO: handle propagated ambiguous errors
- const tai = TT.to_tai(tt)?;
- return tai;
+ const b = TT.to_tai(tt)?;
+ return b;
};
diff --git a/time/chrono/timezone.ha b/time/chrono/timezone.ha
@@ -9,7 +9,7 @@ export type timezone = struct {
// The textual identifier ("Europe/Amsterdam")
name: str,
- // The base timescale (chrono::UTC)
+ // The base timescale (chrono::utc)
timescale: *timescale,
// The duration of a day in this timezone (24 * time::HOUR)
@@ -88,7 +88,7 @@ export fn transform(m: moment, zo: time::duration) moment = {
// Finds, sets and returns a [[moment]]'s currently observed zone
export fn lookupzone(m: *moment) zone = {
if (len(m.loc.zones) == 0) {
- // TODO: what to do? not ideal to assume UTC_Z
+ // TODO: what to do? not ideal to assume UTC
abort("lookup(): timezones should have at least one zone");
};
@@ -140,7 +140,7 @@ export fn lookupzone(m: *moment) zone = {
// Creates a [[timezone]] with a single [[zone]]. Useful for fixed offsets.
// For example, replicate the civil time Hawaii timezone on Earth:
//
-// let hawaii = chrono::fixedzone(&chrono::UTC, chrono::EARTH_DAY,
+// let hawaii = chrono::fixedzone(&chrono::utc, chrono::EARTH_DAY,
// chrono::zone {
// zoffset = -10 * time::HOUR,
// name = "Hawaiian Reef",
@@ -161,15 +161,15 @@ export fn fixedzone(ts: *timescale, daylen: time::duration, z: zone) timezone =
};
// The system's local timezone, set during initialisation
-export const local: locality = &TZ_local;
+export const LOCAL: locality = &TZ_local;
-// TODO: set time::chrono::local to a correct timezone
+// TODO: set time::chrono::LOCAL to a correct timezone
@init fn set_local_timezone() void = {
return;
};
const TZ_local: timezone = timezone {
- name = "Local",
- timescale = &UTC,
+ name = "Local Time",
+ timescale = &utc,
daylength = EARTH_DAY,
zones = [
zone {
@@ -184,11 +184,11 @@ const TZ_local: timezone = timezone {
};
// The UTC (Coordinated Universal Time) "Zulu" timezone
-export const UTC_Z: locality = &TZ_UTC;
+export const UTC: locality = &TZ_UTC;
const TZ_UTC: timezone = timezone {
name = "UTC",
- timescale = &UTC,
+ timescale = &utc,
daylength = EARTH_DAY,
zones = [
zone {
@@ -203,11 +203,11 @@ const TZ_UTC: timezone = timezone {
};
// The TAI (International Atomic Time) "Zulu" timezone
-export const TAI_Z: locality = &TZ_TAI;
+export const TAI: locality = &TZ_TAI;
const TZ_TAI: timezone = timezone {
name = "",
- timescale = &TAI,
+ timescale = &tai,
daylength = EARTH_DAY,
zones = [
zone {
@@ -222,11 +222,11 @@ const TZ_TAI: timezone = timezone {
};
// The MTC (Coordinated Mars Time) "Zulu" timezone
-export const MTC_Z: locality = &TZ_MTC;
+export const MTC: locality = &TZ_MTC;
const TZ_MTC: timezone = timezone {
name = "",
- timescale = &MTC,
+ timescale = &mtc,
daylength = MARS_SOL_MARTIAN,
zones = [
zone {
diff --git a/time/olson/olson.ha b/time/olson/olson.ha
@@ -13,7 +13,7 @@ export type invalidtzif = !void;
// Parses and retrieves a [[chrono::timezone]] from the system zoneinfo
// database, or if applicable, from an internal selection of timezones. All
-// Olson timezones default to using the [[chrono::UTC]] timescale and
+// Olson timezones default to using the [[chrono::utc]] timescale and
// [[chrono::EARTH_DAY]] daylength.
//
// TODO: Tidy up errors.
@@ -21,13 +21,13 @@ export type invalidtzif = !void;
export fn tz(name: str) (chrono::timezone | errors::overflow | fs::error | io::error | invalidtzif) = {
switch (name) {
case "Local" =>
- return *chrono::local;
+ return *chrono::LOCAL;
case "UTC" =>
- return *chrono::UTC_Z;
+ return *chrono::UTC;
case "TAI" =>
- return *chrono::TAI_Z;
+ return *chrono::TAI;
case "MTC" =>
- return *chrono::MTC_Z;
+ return *chrono::MTC;
case =>
void;
};
@@ -45,7 +45,7 @@ export fn tz(name: str) (chrono::timezone | errors::overflow | fs::error | io::e
const file = os::open(fpath)?;
const tz = parse_tzif(file, chrono::timezone {
name = name,
- timescale = &chrono::UTC,
+ timescale = &chrono::utc,
daylength = chrono::EARTH_DAY,
...
})?;