/// <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="interval">The time series interval to align the date and time value onto.</param> /// <returns>The date and time value aligned to the upper time span boundary.</returns> public static DateTime?RoundUpper(this DateTime?value, SeriesInterval interval) { if (value != null) { return(value.Value.RoundUpper(interval.GetSpan().Ticks)); } else { return(null); } }
/// <summary> /// Converts the time series interval unit to the time span value. /// </summary> /// <param name="interval">The time series interval to calculate the time span for.</param> /// <param name="count">The number of time series intervals covered by the series.</param> /// <returns>The time span corresponding to the time series interval unit.</returns> public static TimeSpan GetSpan(this SeriesInterval interval, int count) { switch (interval) { case SeriesInterval.Series1Min: case SeriesInterval.Series5Min: case SeriesInterval.Series15Min: case SeriesInterval.Series30Min: return(TimeFragment.Minute.GetSpan((int)interval * count)); default: throw new ArgumentException($"Unsupported time series interval unit '{interval}'.", nameof(interval)); } }
/// <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="interval">The time series interval to calculate the time span for.</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, SeriesInterval interval, int count) { return(target >= source + interval.GetSpan(count)); }
/// <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="interval">The time series interval to align the date and time value onto.</param> /// <returns>The date and time value aligned to the upper time span boundary.</returns> public static DateTime RoundUpper(this DateTime value, SeriesInterval interval) { return(value.RoundUpper(interval.GetSpan().Ticks)); }
/// <summary> /// Checks if the date and time value is before 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="interval">The time series interval to calculate the time span for.</param> /// <returns>True if the requested date and time value is within the range before the point; otherwise, false.</returns> public static bool IsBefore(this DateTime source, DateTime target, SeriesInterval interval) { return(target <= source + interval.GetSpan()); }