Class MultiDuration
- Namespace
- TimeCockpit.Data.DataModel
- Assembly
- TimeCockpit.Data.dll
Represents a set of durations that belong to this time span. Durations may overlap and can be explicitly flattened if required.
public class MultiDuration
- Inheritance
-
ObjectMultiDuration
- Inherited Members
-
Object.ToString()Object.Equals(Object)Object.Equals(Object, Object)Object.ReferenceEquals(Object, Object)Object.GetHashCode()Object.GetType()Object.MemberwiseClone()
Constructors
MultiDuration(IEnumerable<IDuration>)
Initializes a new instance of the MultiDuration class.
public MultiDuration(IEnumerable<IDuration> parts)
Parameters
partsIEnumerable<IDuration>duration parts of the new multiduration.
MultiDuration(IEnumerable<MultiDuration>)
Initializes a new instance of the MultiDuration class by unionizing the given durations.
public MultiDuration(IEnumerable<MultiDuration> durations)
Parameters
durationsIEnumerable<MultiDuration>duration parts of the new multiduration.
MultiDuration(DateTime, DateTime)
Initializes a new instance of the MultiDuration class. Shorthand version for a single duration.
public MultiDuration(DateTime beginTime, DateTime endTime)
Parameters
beginTimeDateTimebegin time stamp of the duration.
endTimeDateTimeend time stamp of the duration.
Properties
Durations
Gets the durations of this multi-duration.
public IEnumerable<IDuration> Durations { get; }
Property Value
- IEnumerable<IDuration>
EarliestBegin
Gets the earliest begin time
public DateTime EarliestBegin { get; }
Property Value
- DateTime
Flat
Gets a value indicating whether none of the durations overlap.
public bool Flat { get; }
Property Value
- Boolean
LatestEnd
Gets the latest end time.
public DateTime LatestEnd { get; }
Property Value
- DateTime
TotalTime
Gets the total time / sum of the multi duration. Be aware that overlapping times are included in the calculation. Use Flatten before TotalTime if it is required that overlapping times are counted only once.
public TimeSpan TotalTime { get; }
Property Value
- TimeSpan
Methods
And(MultiDuration)
Logical 'and' operation between this and another multi-duration.
public MultiDuration And(MultiDuration other)
Parameters
otherMultiDurationOther multi-duration.
Returns
- MultiDuration
Logical 'and' between this and another multi-duration.
Cut(MultiDuration)
cuts another multi duration by this multi duration. logical "this AND source" result does not contain elements of 0 duration
[Obsolete("Use MultiDuration.And instead. Cut does not offer consistent naming compared to 'and', 'or' and 'subtract'.")]
public MultiDuration Cut(MultiDuration source)
Parameters
sourceMultiDurationSource duration to cut agains this multi duration.
Returns
- MultiDuration
a new multiduration containing the source multiduration cut by this multiduration.
Flatten()
By default, multiple durations might overlap. the flatten method modifies the durations to not overlap and turns two overlapping durations into a single duration.
public void Flatten()
Intersects(DateTime, DateTime)
Checks whether a given duration intersects with any of the durations.
public bool Intersects(DateTime begin, DateTime end)
Parameters
beginDateTimebegin of duration to check
endDateTimeend of duration to check
Returns
- Boolean
true if duration intersects
Intersects(IDuration)
Checks whether a given duration intersects with any of the durations.
public bool Intersects(IDuration duration)
Parameters
durationIDurationduration to check
Returns
- Boolean
true if duration intersects
IsInside(DateTime)
checks whether a given timeStamp is within (or on the border of) any of the durations.
public bool IsInside(DateTime timeStamp)
Parameters
timeStampDateTimetime stamp to check against multi duration.
Returns
- Boolean
Returns true if timeStamp is within any duration.
Or(MultiDuration)
Logical 'or' operation between this and another multi-duration.
public MultiDuration Or(MultiDuration other)
Parameters
otherMultiDurationOther multi-duration.
Returns
- MultiDuration
Logical 'or' between this and another multi-duration.
Subtract(MultiDuration)
Logically subtract another multi-duration from this one.
public MultiDuration Subtract(MultiDuration other)
Parameters
otherMultiDurationOther multi-duration.
Returns
- MultiDuration
Subraction result