From 3d4c9c29eedd81a7a067849015116ace909efe26 Mon Sep 17 00:00:00 2001 From: Dmitriy Khmaladze Date: Fri, 14 Jun 2024 11:53:16 -0400 Subject: [PATCH] #915 span cttor --- src/Azos/Time/HourList.cs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Azos/Time/HourList.cs b/src/Azos/Time/HourList.cs index c20b454b1..f2b46c2f6 100644 --- a/src/Azos/Time/HourList.cs +++ b/src/Azos/Time/HourList.cs @@ -31,13 +31,27 @@ public struct HourList : IEquatable, IJsonWritable, IJsonReadable, IVa /// public struct Span : IEquatable, IComparable { + private void checkInvariants() + { + (StartMinute <= MINUTES_PER_DAY).IsTrue("start <= MINUTES_PER_DAY"); + (DurationMinutes >= 0).IsTrue("dur >= 0"); + (StartMinute + DurationMinutes < MINUTES_PER_DAY * 2).IsTrue("finish < 2 days"); + } - internal Span(int start, int duration) + public Span(int start, int duration) { - (start <= MINUTES_PER_DAY).IsTrue("start <= MINUTES_PER_DAY"); - (duration >= 0 && duration < MINUTES_PER_DAY * 2).IsTrue("duration >= 0 && < MIN_PER-DAY*2"); StartMinute = start; DurationMinutes = duration; + checkInvariants(); + } + + public Span(DateTime start, DateTime end) + { + (start.Kind == end.Kind).IsTrue("sd.kind==ed.kind"); + (start <= end).IsTrue("start<=end"); + StartMinute = start.Minute; + DurationMinutes = (int)(end - start).TotalMinutes; + checkInvariants(); } ///