commit ccea3d200b636503b0072ef4352648de7632c90b
parent b0499b70e5e9fdfed10b3b17cc7c00acea020473
Author: Byron Torres <b@torresjrjr.com>
Date: Thu, 22 Feb 2024 23:43:59 +0000
time::chrono: moment.daytime: i64, not duration
Semantic correction.
Signed-off-by: Byron Torres <b@torresjrjr.com>
Diffstat:
3 files changed, 13 insertions(+), 12 deletions(-)
diff --git a/time/chrono/chronology.ha b/time/chrono/chronology.ha
@@ -33,8 +33,9 @@ export type moment = struct {
// since an abitrary epoch (e.g. the Unix epoch 1970-01-01).
daydate: (void | i64),
- // The observed time-of-day (amount of daytime progressed in a day).
- daytime: (void | time::duration),
+ // The observed time-of-day (amount of daytime progressed in a day)
+ // as nanoseconds.
+ daytime: (void | i64),
};
// Creates a new [[moment]]. Uses a given [[time::instant]] with a [[timescale]]
@@ -83,10 +84,10 @@ export fn daydate(m: *moment) i64 = {
};
// Observes a [[moment]]'s observed time-of-day (amount of daytime progressed in
-// a day) as a [[time::duration]].
-export fn daytime(m: *moment) time::duration = {
+// a day) as nanoseconds.
+export fn daytime(m: *moment) i64 = {
match (m.daytime) {
- case let dt: time::duration =>
+ case let dt: i64 =>
return dt;
case void =>
const (dd, dt) = calc_datetime(
@@ -119,7 +120,7 @@ export fn from_datetime(
loc: locality,
zo: time::duration,
dd: i64,
- dt: time::duration,
+ dt: i64,
) moment = {
const inst = calc_instant(loc.daylength, zo, dd, dt);
return moment {
@@ -136,7 +137,7 @@ fn calc_instant(
day: time::duration, // length of a day
zo: time::duration, // zone offset
dd: i64, // date since epoch
- dt: time::duration, // time since start of day
+ dt: i64, // time since start of day (ns)
) time::instant = {
const daysec = (day / time::SECOND): i64;
const dayrem = day % time::SECOND;
diff --git a/time/date/daytime.ha b/time/date/daytime.ha
@@ -5,7 +5,7 @@ use time;
// Calculates the wall clock (hour, minute, second, nanosecond),
// given a time-of-day (amount of daytime progressed in a day).
-fn calc_hmsn(t: time::duration) (int, int, int, int) = {
+fn calc_hmsn(t: i64) (int, int, int, int) = {
// TODO: Special case for leap seconds, 61st second?
const hour = (t / time::HOUR): int;
const min = ((t / time::MINUTE) % 60): int;
@@ -21,7 +21,7 @@ fn calc_daytime__hmsn(
min: int,
sec: int,
nsec: int,
-) (time::duration | invalid) = {
+) (i64 | invalid) = {
const t = (
(hour * time::HOUR) +
(min * time::MINUTE) +
diff --git a/time/date/virtual.ha b/time/date/virtual.ha
@@ -158,7 +158,7 @@ export fn realize(
};
// determine .daytime
- if (v.daytime is time::duration) {
+ if (v.daytime is i64) {
void;
} else {
const hour = if (v.hour is int) {
@@ -188,7 +188,7 @@ export fn realize(
};
// determine zone offset
- if (v.zoff is time::duration) {
+ if (v.zoff is i64) {
void;
} else {
return insufficient;
@@ -213,7 +213,7 @@ export fn realize(
v.loc,
v.zoff as time::duration,
v.daydate as i64,
- v.daytime as time::duration,
+ v.daytime as i64,
));
// verify zone offset