commit 04b6dbb5225d092d4c7001d824f8012a3729c831
parent e0956ec55d71ccfa8c28e75a28cbd7433a8ef570
Author: Byron Torres <b@torresjrjr.com>
Date: Thu, 7 Mar 2024 00:13:57 +0000
time::chrono: rm eq; add simultaneous, coincident
Breaking-Change: 0.24.0
Signed-off-by: Byron Torres <b@torresjrjr.com>
Diffstat:
4 files changed, 66 insertions(+), 51 deletions(-)
diff --git a/time/chrono/arithmetic.ha b/time/chrono/arithmetic.ha
@@ -3,22 +3,36 @@
use time;
-// Compares two [[moment]]s. Returns -1 if a precedes b, 0 if a and b are
-// simultaneous, or +1 if b precedes a.
+// Returns true if two [[moment]]s represent the same time in the same locality,
+// which is to say that their [[locality]] and [[time::instant]] are both equal.
+// Their observed values and representations in a chronology should be the same
+// in all cases.
+//
+// See [[simultaneous]] to determine if two moments represent the same moment in
+// time regardless of locality.
+export fn coincident(a: *moment, b: *moment) bool = {
+ return a.loc == b.loc && a.sec == b.sec && a.nsec == b.nsec;
+};
+
+// Returns true if two [[moment]]s represent the same moment in time, regardless
+// of locality.
//
// The moments are compared as [[time::instant]]s; their observed chronological
-// values are ignored.
+// values and representations are ignored.
//
// If the moments' associated [[timescale]]s are different, they will be
// converted to [[tai]] instants first. Any [[discontinuity]] occurence will be
// returned. If a discontinuity against TAI amongst the two timescales exist,
// consider converting such instants manually.
-export fn compare(a: *moment, b: *moment) (i8 | discontinuity) = {
- const (ia, ib) = convertpair(a, b)?;
- return time::compare(ia, ib);
+//
+// See [[coincident]] to determine if two [[moment]]s are equal with respect to
+// both time and locality.
+export fn simultaneous(a: *moment, b: *moment) (bool | discontinuity) = {
+ return 0 == compare(a, b)?;
};
-// Returns true if moments a & b are equivalent; otherwise, returns false.
+// Compares two [[moment]]s. Returns -1 if a precedes b, 0 if a and b are
+// simultaneous, or +1 if b precedes a.
//
// The moments are compared as [[time::instant]]s; their observed chronological
// values are ignored.
@@ -27,8 +41,9 @@ export fn compare(a: *moment, b: *moment) (i8 | discontinuity) = {
// converted to [[tai]] instants first. Any [[discontinuity]] occurence will be
// returned. If a discontinuity against TAI amongst the two timescales exist,
// consider converting such instants manually.
-export fn eq(a: *moment, b: *moment) (bool | discontinuity) = {
- return 0 == compare(a, b)?;
+export fn compare(a: *moment, b: *moment) (i8 | discontinuity) = {
+ const (ia, ib) = convertpair(a, b)?;
+ return time::compare(ia, ib);
};
// Returns the [[time::duration]] between two [[moment]]s, from a to b.
diff --git a/time/date/date.ha b/time/date/date.ha
@@ -274,7 +274,7 @@ export fn from_str(
match (expect) {
case let e: date =>
assert(actual is date, "wanted 'date', got 'error'");
- assert(chrono::eq(&(actual as date), &e)!,
+ assert(chrono::simultaneous(&(actual as date), &e)!,
"incorrect 'date' value");
case let e: parsefail =>
assert(actual is parsefail,
diff --git a/time/date/parithm.ha b/time/date/parithm.ha
@@ -348,47 +348,47 @@ export fn truncate(d: date, u: unit) date = {
@test fn truncate() void = {
const d = new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 1, 2)!;
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::ERA),
&new(chrono::UTC, 0, 1, 1, 1, 0, 0, 0, 0)!)!,
"invalid truncate() result 01");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::YEAR),
&new(chrono::UTC, 0, 1994, 1, 1, 0, 0, 0, 0)!)!,
"invalid truncate() result 02");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::MONTH),
&new(chrono::UTC, 0, 1994, 8, 1, 0, 0, 0, 0)!)!,
"invalid truncate() result 03");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::WEEK),
&new(chrono::UTC, 0, 1994, 8, 22, 0, 0, 0, 0)!)!,
"invalid truncate() result 04");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::DAY),
&new(chrono::UTC, 0, 1994, 8, 27, 0, 0, 0, 0)!)!,
"invalid truncate() result 05");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::HOUR),
&new(chrono::UTC, 0, 1994, 8, 27, 11, 0, 0, 0)!)!,
"invalid truncate() result 06");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::MINUTE),
&new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 0, 0)!)!,
"invalid truncate() result 07");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::SECOND),
&new(chrono::UTC, 0, 1994, 8, 27, 11, 20, 1, 0)!)!,
"invalid truncate() result 08");
- assert(chrono::eq(
+ assert(chrono::simultaneous(
&truncate(d, unit::NANOSECOND),
&d)!,
"invalid truncate() result 09");
diff --git a/time/date/reckon.ha b/time/date/reckon.ha
@@ -273,15 +273,15 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
let a = new(chrono::UTC, 0)!;
let r = reckon(a, 0, p);
- assert(chrono::eq(&a, &r)!, "01. incorrect result");
+ assert(chrono::simultaneous(&a, &r)!, "01. incorrect result");
let a = new(chrono::UTC, 0, 2019, 12, 27, 21, 7, 8, 0)!;
let r = reckon(a, 0, p);
- assert(chrono::eq(&a, &r)!, "02. incorrect result");
+ assert(chrono::simultaneous(&a, &r)!, "02. incorrect result");
let a = new(chrono::UTC, 0, 1970, 1, 1, 0, 0, 0, 0)!;
let r = reckon(a, 0, p);
- assert(chrono::eq(&a, &r)!, "03. incorrect result");
+ assert(chrono::simultaneous(&a, &r)!, "03. incorrect result");
// generic periods, calculus::CEIL
@@ -298,7 +298,7 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
...
});
let b = new(chrono::UTC, 0, 2021, 1, 28, 22, 8, 9, 1)!;
- assert(chrono::eq(&b, &r)!, "04. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "04. incorrect result");
let r = reckon(a, 0, period {
years = -1,
@@ -311,7 +311,7 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
...
});
let b = new(chrono::UTC, 0, 2018, 11, 26, 20, 6, 6, 999999999)!;
- assert(chrono::eq(&b, &r)!, "05. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "05. incorrect result");
let r = reckon(a, 0, period {
years = 100,
@@ -324,7 +324,7 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
...
});
let b = new(chrono::UTC, 0, 2128, 8, 10, 2, 48, 48, 100)!;
- assert(chrono::eq(&b, &r)!, "06. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "06. incorrect result");
let r = reckon(a, 0, period {
years = -100,
@@ -337,14 +337,14 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
...
});
let b = new(chrono::UTC, 0, 1911, 5, 15, 15, 25, 27, 999999900)!;
- assert(chrono::eq(&b, &r)!, "07. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "07. incorrect result");
let r = reckon(a, 0, period {
weeks = 100,
...
});
let b = new(chrono::UTC, 0, 2021, 11, 26, 21, 7, 8, 0)!;
- assert(chrono::eq(&b, &r)!, "08. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "08. incorrect result");
// calculus, February 29 overflows
@@ -353,19 +353,19 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
let r = reckon(a, calculus::FLOOR, p);
let b = new(chrono::UTC, 0, 2000, 2, 1)!;
- assert(chrono::eq(&b, &r)!, "09. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "09. incorrect result");
let r = reckon(a, calculus::CEIL, p);
let b = new(chrono::UTC, 0, 2000, 2, 29)!;
- assert(chrono::eq(&b, &r)!, "10. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "10. incorrect result");
let r = reckon(a, calculus::HOP, p);
let b = new(chrono::UTC, 0, 2000, 3, 1)!;
- assert(chrono::eq(&b, &r)!, "11. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "11. incorrect result");
let r = reckon(a, calculus::FOLD, p);
let b = new(chrono::UTC, 0, 2000, 3, 2)!;
- assert(chrono::eq(&b, &r)!, "12. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "12. incorrect result");
// calculus, February 28 overflows
@@ -374,19 +374,19 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
let r = reckon(a, calculus::FLOOR, p);
let b = new(chrono::UTC, 0, 2001, 2, 1)!;
- assert(chrono::eq(&b, &r)!, "13. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "13. incorrect result");
let r = reckon(a, calculus::CEIL, p);
let b = new(chrono::UTC, 0, 2001, 2, 28)!;
- assert(chrono::eq(&b, &r)!, "14. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "14. incorrect result");
let r = reckon(a, calculus::HOP, p);
let b = new(chrono::UTC, 0, 2001, 3, 1)!;
- assert(chrono::eq(&b, &r)!, "15. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "15. incorrect result");
let r = reckon(a, calculus::FOLD, p);
let b = new(chrono::UTC, 0, 2001, 3, 3)!;
- assert(chrono::eq(&b, &r)!, "16. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "16. incorrect result");
// multiple periods
@@ -404,35 +404,35 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
let r = reckon(a, 0, ps[..1]...);
let b = new(chrono::UTC, 0, 2002, 2, 1)!;
- assert(chrono::eq(&b, &r)!, "17. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "17. incorrect result");
let r = reckon(a, 0, ps[..2]...);
let b = new(chrono::UTC, 0, 2000, 12, 31)!;
- assert(chrono::eq(&b, &r)!, "18. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "18. incorrect result");
let r = reckon(a, 0, ps[..3]...);
let b = new(chrono::UTC, 0, 1999, 11, 29)!;
- assert(chrono::eq(&b, &r)!, "19. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "19. incorrect result");
let r = reckon(a, 0, ps[..4]...);
let b = new(chrono::UTC, 0, 2000, 12, 30)!;
- assert(chrono::eq(&b, &r)!, "20. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "20. incorrect result");
let r = reckon(a, 0, ps[..5]...);
let b = new(chrono::UTC, 0, 2000, 12, 30, 1, 1, 1)!;
- assert(chrono::eq(&b, &r)!, "21. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "21. incorrect result");
let r = reckon(a, 0, ps[..6]...);
let b = new(chrono::UTC, 0, 2000, 12, 30)!;
- assert(chrono::eq(&b, &r)!, "22. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "22. incorrect result");
let r = reckon(a, 0, ps[..7]...);
let b = new(chrono::UTC, 0, 2000, 12, 29, 22, 58, 59)!;
- assert(chrono::eq(&b, &r)!, "23. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "23. incorrect result");
let r = reckon(a, 0, ps[..8]...);
let b = new(chrono::UTC, 0, 2000, 12, 30)!;
- assert(chrono::eq(&b, &r)!, "24. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "24. incorrect result");
// multiple periods, calculus::REVSIG
@@ -450,35 +450,35 @@ fn reckon_nanoseconds(r: *virtual, nsecs: i64, calc: calculus) void = {
let r = reckon(a, calculus::REVSIG, ps[..1]...);
let b = new(chrono::UTC, 0, 2002, 2, 1)!;
- assert(chrono::eq(&b, &r)!, "25. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "25. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..2]...);
let b = new(chrono::UTC, 0, 2000, 12, 31)!;
- assert(chrono::eq(&b, &r)!, "26. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "26. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..3]...);
let b = new(chrono::UTC, 0, 1999, 11, 30)!;
- assert(chrono::eq(&b, &r)!, "27. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "27. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..4]...);
let b = new(chrono::UTC, 0, 2001, 1, 1)!;
- assert(chrono::eq(&b, &r)!, "28. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "28. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..5]...);
let b = new(chrono::UTC, 0, 2001, 1, 1, 1, 1, 1)!;
- assert(chrono::eq(&b, &r)!, "29. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "29. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..6]...);
let b = new(chrono::UTC, 0, 2001, 1, 1)!;
- assert(chrono::eq(&b, &r)!, "30. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "30. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..7]...);
let b = new(chrono::UTC, 0, 2000, 12, 31, 22, 58, 59)!;
- assert(chrono::eq(&b, &r)!, "31. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "31. incorrect result");
let r = reckon(a, calculus::REVSIG, ps[..8]...);
let b = new(chrono::UTC, 0, 2001, 1, 1)!;
- assert(chrono::eq(&b, &r)!, "32. incorrect result");
+ assert(chrono::simultaneous(&b, &r)!, "32. incorrect result");
return;
};