Created
June 30, 2020 11:08
-
-
Save Jogai/63b47ba220de215b70f154680ea7bac3 to your computer and use it in GitHub Desktop.
Check overlap in date ranges
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
using System; | |
using System.Collections.Generic; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
var init = new { from = new DateTime(2020, 5, 10), to = new DateTime(2020, 5, 20)}; | |
var x = new List<(DateTime StartsOn, DateTime EndsOn, Boolean expected)>() { | |
{(new DateTime(2020, 4, 20), new DateTime(2020, 4, 25), false)}, //Before | |
{(new DateTime(2020, 5, 22), new DateTime(2020, 10, 28), false)}, //After | |
{(new DateTime(2020, 5, 12), new DateTime(2020, 5, 18), true)}, //Between | |
{(new DateTime(2020, 5, 8), new DateTime(2020, 5, 12), true)}, //FirstFew | |
{(new DateTime(2020, 5, 18), new DateTime(2020, 5, 22), true)}, //LastFew | |
}; | |
foreach (var d in x) | |
{ | |
var actual = d.StartsOn <= init.to && d.EndsOn >= init.from; | |
Console.WriteLine($"{(actual != d.expected ? '❌' : '✅')} {actual} should be {d.expected} "); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment