[monotouch-test] Tweak CalendarTest yet again. (#3015)

Hopefully third time's the charm...

Don't do date math (adding hours) to a local datetime, since DST *will* muddy
the waters and prove that 1=2.

Instead convert the date we want to calculate on to UTC, which should be DST-agnostic.

I've tested this by running the test for every hour during the next 10 years,
so that should cover mostly everything (although I'm still waiting for the
Delorean I ordered to be able to test both in the future and the past).

Previous attempts:

0442cdf9c0
5caddb3571

Should fix https://github.com/xamarin/maccore/issues/573.
This commit is contained in:
Rolf Bjarne Kvinge 2017-11-16 18:48:37 +01:00 коммит произвёл GitHub
Родитель d2d2fcb352
Коммит 171cf4987c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
1 изменённых файлов: 3 добавлений и 2 удалений

Просмотреть файл

@ -34,7 +34,7 @@ namespace MonoTouchFixtures.Foundation {
public void DateComponentsTest ()
{
var cal = new NSCalendar (NSCalendarType.Gregorian);
var now = DateTime.Now.ToUniversalTime ();
var now = DateTime.Now;
NSDateComponents comps;
comps = cal.Components (NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, (NSDate) now);
@ -42,7 +42,8 @@ namespace MonoTouchFixtures.Foundation {
Assert.AreEqual (now.Month, comps.Month, "a month");
Assert.AreEqual (now.Day, comps.Day, "a day");
comps = cal.Components (NSCalendarUnit.Hour, (NSDate) now.AddHours (-1), (NSDate) now, NSDateComponentsWrappingBehavior.None);
var dayCompare = now.ToUniversalTime ();
comps = cal.Components (NSCalendarUnit.Hour, (NSDate) dayCompare.AddHours (-1), (NSDate) dayCompare, NSDateComponentsWrappingBehavior.None);
Assert.AreEqual (1, comps.Hour, "b hour");
}