Beispiel #1
0
 /// <summary>
 /// Initializes new instance of a time interval from the interfaces an upper and a lower interval reference values.
 /// </summary>
 /// <param name="upper">The interface to the upper interval boundary to set the interval with.</param>
 /// <param name="lower">The interface to the lower interval boundary to set the interval with.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(IIntervalUpper <DateTime> upper, IIntervalLower <DateTime> lower, IntervalType type = IntervalType.Flex)
 {
     _limits = IntervalLimits.Lower | IntervalLimits.Upper;
     if (upper != null)
     {
         if (upper.UpperInclude)
         {
             _limits &= ~IntervalLimits.Lower;
         }
         _lower = upper.Upper;
     }
     if (lower != null)
     {
         if (upper == null)
         {
             _lower = lower.Lower;
         }
         if (lower.LowerInclude)
         {
             _limits &= ~IntervalLimits.Upper;
         }
         _upper = lower.Lower;
     }
     _span = _upper - _lower;
     Type  = type;
 }
Beispiel #2
0
 /// <summary>
 /// Initializes new instance of a time interval from a time span value.
 /// </summary>
 /// <param name="span">The time span to use as a length of a new time interval.</param>
 /// <param name="limits">The interval boundary inclusion flags that defines the boundary mode.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(TimeSpan?span, IntervalLimits limits, IntervalType type = IntervalType.Flex)
 {
     _limits = limits;
     if (span < TimeSpan.Zero)
     {
         span = TimeSpan.Zero;
     }
     _span = span;
     Type  = type;
 }
Beispiel #3
0
 /// <summary>
 /// Initializes new instance of a time interval from a time span value.
 /// </summary>
 /// <param name="span">The time span to use as a length of a new time interval.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(TimeSpan?span, IntervalType type = IntervalType.Flex)
 {
     _limits = IntervalLimits.Lower | IntervalLimits.Upper;
     if (span < TimeSpan.Zero)
     {
         span = TimeSpan.Zero;
     }
     _span = span;
     Type  = type;
 }
Beispiel #4
0
 /// <summary>
 /// Initializes new instance of a time interval from a lower date and time reference value and a time span values.
 /// </summary>
 /// <param name="time">The date and time of a lower boundary to set the interval with.</param>
 /// <param name="span">The time span to use as a length of a new time interval.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(DateTime?time, TimeSpan?span, IntervalType type = IntervalType.Flex)
 {
     _limits = IntervalLimits.Lower | IntervalLimits.Upper;
     _lower  = time;
     if (span < TimeSpan.Zero)
     {
         span = TimeSpan.Zero;
     }
     _upper = time + span;
     _span  = span;
     Type   = type;
 }
Beispiel #5
0
 /// <summary>
 /// Initializes new instance of a time interval from an existing time interval.
 /// </summary>
 /// <param name="source">The time interval to get the interval parameters from.</param>
 public TimeInterval(TimeInterval source)
 {
     if (source != null)
     {
         _limits = source._limits;
         _lower  = source._lower;
         _upper  = source._upper;
         _span   = _upper - _lower;
         Type    = source.Type;
     }
     else
     {
         throw new ArgumentNullException(nameof(source));
     }
 }
Beispiel #6
0
 /// <summary>
 /// Initializes new instance of a time interval from an upper and a lower date and time reference values.
 /// </summary>
 /// <param name="lower">The lower date and time interval boundary to set the interval with.</param>
 /// <param name="upper">The upper date and time interval boundary to set the interval with.</param>
 /// <param name="limits">The interval boundary inclusion flags that defines the boundary mode.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(DateTime?lower, DateTime?upper, IntervalLimits limits, IntervalType type = IntervalType.Flex)
 {
     _limits = limits;
     _lower  = lower;
     if (lower == null || upper == null || upper > lower)
     {
         _upper = upper;
     }
     else
     {
         _upper = lower;
     }
     _span = _upper - _lower;
     Type  = type;
 }
Beispiel #7
0
 /// <summary>
 /// Initializes new instance of a time interval from an existing time interval.
 /// </summary>
 /// <param name="interval">The time interval to get the interval parameters from.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(IInterval <DateTime> interval, IntervalType type = IntervalType.Flex)
 {
     if (interval != null)
     {
         if (interval.LowerInclude)
         {
             _limits |= IntervalLimits.Lower;
         }
         if (interval.UpperInclude)
         {
             _limits |= IntervalLimits.Upper;
         }
         _lower = interval.Lower;
         _upper = interval.Upper;
         _span  = _upper - _lower;
     }
     Type = type;
 }
Beispiel #8
0
 /// <summary>
 /// Initializes new instance of a time interval from a time interval source and target reference values.
 /// </summary>
 /// <param name="limits">The interval boundary inclusion flags that defines the boundary mode.</param>
 /// <param name="source">The source time interval to get the interval parameters from.</param>
 /// <param name="target">The target time interval to adjust the source interval with.</param>
 public TimeInterval(TimeInterval source, IInterval <DateTime> target, IntervalLimits limits)
 {
     if (source != null)
     {
         if (target != null)
         {
             _limits = source._limits;
             if ((limits & IntervalLimits.Lower) != IntervalLimits.None)
             {
                 if (target.UpperInclude)
                 {
                     _limits &= ~IntervalLimits.Lower;
                 }
                 _lower = target.Upper;
             }
             else
             {
                 _lower = source._lower;
             }
             if ((limits & IntervalLimits.Upper) != IntervalLimits.None)
             {
                 if (target.LowerInclude)
                 {
                     _limits &= ~IntervalLimits.Upper;
                 }
                 _upper = target.Lower;
             }
             else
             {
                 _upper = source._upper;
             }
             _span = _upper - _lower;
             Type  = source.Type;
         }
         else
         {
             throw new ArgumentNullException(nameof(target));
         }
     }
     else
     {
         throw new ArgumentNullException(nameof(source));
     }
 }
Beispiel #9
0
 /// <summary>
 /// Initializes new instance of a time interval from a lower date and time reference value.
 /// </summary>
 /// <param name="time">The date and time of a lower boundary to set the interval with.</param>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(DateTime?time, IntervalType type = IntervalType.Flex)
 {
     _limits = IntervalLimits.Lower | IntervalLimits.Upper;
     _lower  = time;
     Type    = type;
 }
Beispiel #10
0
 /// <summary>
 /// Initializes new instance of a time interval.
 /// </summary>
 /// <param name="type">The time interval flexibility mode to set to the time interval.</param>
 public TimeInterval(IntervalType type = IntervalType.Flex)
 {
     _limits = IntervalLimits.Lower | IntervalLimits.Upper;
     Type    = type;
 }