Created
May 3, 2015 21:20
-
-
Save bjartwolf/7408dcacfa39399aa8ea to your computer and use it in GitHub Desktop.
This file contains hidden or 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
let getLastSundays year = | |
let lastSundays = Dictionary<int, int>() | |
// find all lastsundays | |
[for month in 1..12-> | |
[for day in System.DateTime.DaysInMonth(year,month).. -1.. 1-> | |
System.DateTime(year,month,day).DayOfWeek,(month,day)] | |
|> Seq.find (fun (dayOfWeek,_) -> dayOfWeek = System.DayOfWeek.Sunday) ] | |
|> Seq.map (fun ((_,x)) -> x) |> Seq.iter lastSundays.Add | |
lastSundays | |
[<TestClass>] | |
type UnitTest() = | |
[<TestMethod>] | |
[<TestCategory("Unit")>] | |
member x.TestDayLightSavingsIn2015() = | |
Assert.AreEqual(23, findHoursInNorwegianDay 2015 3 29) | |
Assert.AreEqual(25, findHoursInNorwegianDay 2015 10 25) | |
Assert.AreEqual(24, findHoursInNorwegianDay 2015 4 27) | |
[<TestMethod>] | |
[<TestCategory("Unit")>] | |
member x.DayLightSavingsProperties() = | |
let datetest (date :System.DateTime) = | |
let lastSunday = (getLastSundays date.Year).[date.Month] | |
if (date.Year < 1997) then | |
true // summertime was really strange before and we don't need to cover the past | |
else if (date.Month = 3 && date.DayOfWeek = DayOfWeek.Sunday && date.Day = lastSunday) then | |
23 = findHoursInNorwegianDay date.Year date.Month date.Day | |
else if (date.Month = 10 && date.DayOfWeek = DayOfWeek.Sunday && date.Day = lastSunday) then | |
25 = findHoursInNorwegianDay date.Year date.Month date.Day | |
else | |
24 = findHoursInNorwegianDay date.Year date.Month date.Day | |
Check.One({Config.Quick with MaxTest = 10000}, datetest) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment