Exemple #1
0
 /// <summary>
 /// Aligns the date and time value to the upper boundary of a time span.
 /// </summary>
 /// <param name="value">The date and time value that needs to be snapped onto the interval span.</param>
 /// <param name="count">The time span in time units to align the date and time value onto.</param>
 /// <param name="unit">The time span unit covered by the time series interval.</param>
 /// <returns>The date and time value aligned to the upper time span boundary.</returns>
 public static DateTime?RoundUpper(this DateTime?value, int count, TimeFragment unit = TimeFragment.Minute)
 {
     if (value != null)
     {
         return(value.Value.RoundUpper(unit.GetSpan(count).Ticks));
     }
     else
     {
         return(null);
     }
 }
Exemple #2
0
        /// <summary>
        /// Converts the date and time fragment unit to the time span value.
        /// </summary>
        /// <param name="unit">The date and time fragment unit covered by the interval.</param>
        /// <param name="count">The number of time unit intervals covered by the series.</param>
        /// <returns>The time span corresponding to time fragment unit.</returns>
        public static TimeSpan GetSpan(this TimeFragment unit, int count)
        {
            switch (unit)
            {
            case TimeFragment.Day:
                return(TimeSpan.FromDays(count));

            case TimeFragment.Hour:
                return(TimeSpan.FromHours(count));

            case TimeFragment.Minute:
                return(TimeSpan.FromMinutes(count));

            case TimeFragment.Second:
                return(TimeSpan.FromSeconds(count));

            default:
                throw new ArgumentException($"Unsupported time fragment span unit '{unit}'.", nameof(unit));
            }
        }
Exemple #3
0
 /// <summary>
 /// Aligns the date and time value to the upper boundary of a time span.
 /// </summary>
 /// <param name="value">The date and time value that needs to be snapped onto the interval span.</param>
 /// <param name="count">The time span in time units to align the date and time value onto.</param>
 /// <param name="unit">The time span unit covered by the time series interval.</param>
 /// <returns>The date and time value aligned to the upper time span boundary.</returns>
 public static DateTime RoundUpper(this DateTime value, int count, TimeFragment unit = TimeFragment.Minute)
 {
     return(value.RoundUpper(unit.GetSpan(count).Ticks));
 }
Exemple #4
0
 /// <summary>
 /// Checks if the date and time value is after the reference point within specified number of intervals.
 /// </summary>
 /// <param name="source">The date and time reference point to check the vicinity for.</param>
 /// <param name="target">The date and time value to check the vicinity for.</param>
 /// <param name="unit">The date and time fragment unit covered by the interval.</param>
 /// <param name="count">The number of time series intervals to check around.</param>
 /// <returns>True if the requested date and time value is within the range after the point; otherwise, false.</returns>
 public static bool IsAfter(this DateTime source, DateTime target, TimeFragment unit, int count)
 {
     return(target >= source + unit.GetSpan(count));
 }