commit 9cc88902292e75e3a17a69a205f66b8ad1735d6e
parent 9bbbe783ab8857106bd4cd449501babb581a981f
Author: Vlad-Stefan Harbuz <vlad@vladh.net>
Date: Fri, 7 Jan 2022 17:27:48 +0100
add period_eq()
Signed-off-by: Vlad-Stefan Harbuz <vlad@vladh.net>
Diffstat:
1 file changed, 13 insertions(+), 0 deletions(-)
diff --git a/datetime/arithmetic.ha b/datetime/arithmetic.ha
@@ -93,6 +93,19 @@ export fn diff(a: datetime, b: datetime) period = {
return period { ... };
};
+// Returns whether or not two periods are numerically equal
+export fn period_eq(a: period, b: period) bool = {
+ return a.eras == b.eras &&
+ a.years == b.years &&
+ a.months == b.months &&
+ a.weeks == b.weeks &&
+ a.days == b.days &&
+ a.hours == b.hours &&
+ a.minutes == b.minutes &&
+ a.seconds == b.seconds &&
+ a.nanoseconds == b.nanoseconds;
+};
+
// Hops, starting from a datetime, to static inter-period points along the
// calendar, according to the given periods, and returns a new datetime.
// Inter-period points are the starts of years, months, days, etc.