Created
March 23, 2017 00:13
-
-
Save jacobtoye/9645c847c8b077a13b36700f1be16b5d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class OverspeedPeriodExtensions | |
{ | |
public static IQueryable<OverspeedPeriod> WithRemoteId(this IQueryable<OverspeedPeriod> overspeedPeriods, params int[] remoteIds) | |
{ | |
return overspeedPeriods.Where(l => remoteIds.Contains(l.RemoteId)); | |
} | |
/// <summary> | |
/// Filters by all periods that start within date range. | |
/// | |
/// E.g. returns C and D | |
/// | |
/// | | | |
/// A [---] | | | |
/// B [-+-] | | |
/// C | [---] | | |
/// D | [-+-] | |
/// E | | | |
/// F | | [---] | |
/// G [-+-----------+-] | |
/// | | | |
/// | |
/// </summary> | |
public static IQueryable<OverspeedPeriod> StartsWithin(this IQueryable<OverspeedPeriod> overspeedPeriods, DateTime minDate, DateTime maxDate) | |
{ | |
return overspeedPeriods.Where(p => p.StartTime >= minDate && p.StartTime < maxDate); | |
} | |
/// <summary> | |
/// Filters by all periods that end within date range. | |
/// | |
/// E.g. returns B and C | |
/// | |
/// | | | |
/// A [---] | | | |
/// B [-+-] | | |
/// C | [---] | | |
/// D | [-+-] | |
/// E | | | |
/// F | | [---] | |
/// G [-+-----------+-] | |
/// | | | |
/// | |
/// </summary> | |
public static IQueryable<OverspeedPeriod> EndsWithin(this IQueryable<OverspeedPeriod> overspeedPeriods, DateTime minDate, DateTime maxDate) | |
{ | |
return overspeedPeriods.Where(p => p.EndTime >= minDate && p.EndTime < maxDate); | |
} | |
/// <summary> | |
/// Filters by all periods that are only fully contained within date range. | |
/// | |
/// E.g. returns only C | |
/// | |
/// | | | |
/// A [---] | | | |
/// B [-+-] | | |
/// C | [---] | | |
/// D | [-+-] | |
/// E | | | |
/// F | | [---] | |
/// G [-+-----------+-] | |
/// | | | |
/// | |
/// </summary> | |
public static IQueryable<OverspeedPeriod> ContainedWithin(this IQueryable<OverspeedPeriod> overspeedPeriods, DateTime minDate, DateTime maxDate) | |
{ | |
return overspeedPeriods.Where(p => p.StartTime >= minDate && p.EndTime < maxDate); | |
} | |
/// <summary> | |
/// Gets all overspeed periods that either starts within, ends with, is contained or overlaps date range. | |
/// | |
/// E.g. return B, C, D, G | |
/// | |
/// | | | |
/// A [---] | | | |
/// B [-+-] | | |
/// C | [---] | | |
/// D | [-+-] | |
/// E | | | |
/// F | | [---] | |
/// G [-+-----------+-] | |
/// | | | |
/// | |
/// </summary> | |
public static IQueryable<OverspeedPeriod> Intersects(this IQueryable<OverspeedPeriod> overspeedPeriods, DateTime minDate, DateTime maxDate) | |
{ | |
return overspeedPeriods.Where(p => p.EndTime >= minDate && p.StartTime < maxDate); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment