Fix issue with Date diff when it includes a Daylight Saving Time (#193)
The application uses local time to calculate the number of days between 2 dates. If a Daylight Saving Time takes place during this period of time (only Clocks Forward 2am->3am), the application will miss 1 day and fail to calculate the number of days/weeks/months between the 2 dates. image Description of the changes: DateCalculationEngine uses local time to modify dates, however, AddDays, AddWeeks,... won't add 24 hours or 7 days if DST happens between the 2 dates, but instead add ~23.9/24.1 hours or ~6.9/7.1 days (depends if it's the DST clock backward or clock forward). When the DST is clock forward, DateCalculationEngine will miss one day. Solution use UTC dates to calculate date difference. Extra Fix: use calendar->FirstPeriodInThisDay and calendar->FirstHourInThisPeriod in ClipTime (else it will set the time to 12PM (noon) in some regions. replace OBSERVABLE_PROPERTY_RW by OBSERVABLE_PROPERTY_R when possible. remove the definition of CheckClipTimeSameDay (implementation missing) How changes were validated: Tested manually with different regions (FR, US, ES, JP). Fixes #178
This commit is contained in:
committed by
Howard Wolosky
parent
e40791d7ad
commit
cd7c266a6b
@@ -387,6 +387,63 @@ namespace DateCalculationUnitTests
|
||||
VERIFY_IS_TRUE(StringReference(L"") != viewModel->StrDateResult);
|
||||
}
|
||||
|
||||
TEST_METHOD(DateCalcViewModelDateDiffDaylightSavingTimeTest)
|
||||
{
|
||||
auto viewModel = ref new DateCalculatorViewModel();
|
||||
|
||||
viewModel->IsDateDiffMode = true;
|
||||
VERIFY_IS_TRUE(viewModel->IsDateDiffMode);
|
||||
|
||||
// 29.02.2008
|
||||
viewModel->FromDate = DateUtils::SystemTimeToDateTime(datetimeDifftest[5].startDate);
|
||||
// 31.03.2008
|
||||
viewModel->ToDate = DateUtils::SystemTimeToDateTime(datetimeDifftest[5].endDate);
|
||||
|
||||
//// Assert for the result
|
||||
VERIFY_IS_FALSE(viewModel->IsDiffInDays);
|
||||
VERIFY_ARE_EQUAL(StringReference(L"31 days"), viewModel->StrDateDiffResultInDays);
|
||||
VERIFY_ARE_EQUAL(StringReference(L"1 month, 2 days"), viewModel->StrDateDiffResult);
|
||||
|
||||
// Daylight Saving Time - Clock Forward
|
||||
// 10.03.2019
|
||||
SYSTEMTIME startDate;
|
||||
startDate.wYear = 2019;
|
||||
startDate.wMonth = 03;
|
||||
startDate.wDay = 10;
|
||||
startDate.wDayOfWeek = 0;
|
||||
startDate.wHour = startDate.wMinute = 0;
|
||||
startDate.wSecond = startDate.wMilliseconds = 0;
|
||||
viewModel->FromDate = DateUtils::SystemTimeToDateTime(startDate);
|
||||
// 11.03.2019
|
||||
SYSTEMTIME endDate;
|
||||
endDate.wYear = 2019;
|
||||
endDate.wMonth = 03;
|
||||
endDate.wDay = 11;
|
||||
endDate.wDayOfWeek = 0;
|
||||
endDate.wHour = endDate.wMinute = 0;
|
||||
endDate.wSecond = endDate.wMilliseconds = 0;
|
||||
viewModel->ToDate = DateUtils::SystemTimeToDateTime(endDate);
|
||||
VERIFY_IS_TRUE(viewModel->IsDiffInDays);
|
||||
VERIFY_ARE_EQUAL(StringReference(L"1 day"), viewModel->StrDateDiffResult);
|
||||
|
||||
endDate.wDay += 6;
|
||||
viewModel->ToDate = DateUtils::SystemTimeToDateTime(endDate);
|
||||
VERIFY_IS_FALSE(viewModel->IsDiffInDays);
|
||||
VERIFY_ARE_EQUAL(StringReference(L"1 week"), viewModel->StrDateDiffResult);
|
||||
|
||||
// Daylight Saving Time - Clock Backward
|
||||
// 03.11.2019
|
||||
startDate.wMonth = 11;
|
||||
startDate.wDay = 03;
|
||||
viewModel->FromDate = DateUtils::SystemTimeToDateTime(startDate);
|
||||
// 04.11.2019
|
||||
endDate.wMonth = 11;
|
||||
endDate.wDay = 04;
|
||||
viewModel->ToDate = DateUtils::SystemTimeToDateTime(endDate);
|
||||
VERIFY_IS_TRUE(viewModel->IsDiffInDays);
|
||||
VERIFY_ARE_EQUAL(StringReference(L"1 day"), viewModel->StrDateDiffResult);
|
||||
}
|
||||
|
||||
TEST_METHOD(DateCalcViewModelAddTest)
|
||||
{
|
||||
// TODO - MSFT 10331900, fix this test
|
||||
|
Reference in New Issue
Block a user