Convert DateCalculatorViewModel to runtime class (#769)
This commit is contained in:
parent
577aafb3f4
commit
caa1c6bb9d
@ -9,6 +9,11 @@ using namespace Windows::Foundation;
|
|||||||
using namespace Windows::Globalization;
|
using namespace Windows::Globalization;
|
||||||
using namespace CalculatorApp::Common::DateCalculation;
|
using namespace CalculatorApp::Common::DateCalculation;
|
||||||
|
|
||||||
|
bool operator==(const DateDifference& l, const DateDifference& r)
|
||||||
|
{
|
||||||
|
return l.year == r.year && l.month == r.month && l.week == r.week && l.day == r.day;
|
||||||
|
}
|
||||||
|
|
||||||
DateCalculationEngine::DateCalculationEngine(_In_ String ^ calendarIdentifier)
|
DateCalculationEngine::DateCalculationEngine(_In_ String ^ calendarIdentifier)
|
||||||
{
|
{
|
||||||
m_calendar = ref new Calendar();
|
m_calendar = ref new Calendar();
|
||||||
@ -18,10 +23,9 @@ DateCalculationEngine::DateCalculationEngine(_In_ String ^ calendarIdentifier)
|
|||||||
|
|
||||||
// Adding Duration to a Date
|
// Adding Duration to a Date
|
||||||
// Returns: True if function succeeds to calculate the date else returns False
|
// Returns: True if function succeeds to calculate the date else returns False
|
||||||
bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const DateDifference& duration, _Out_ DateTime* endDate)
|
IBox<DateTime> ^ DateCalculationEngine::AddDuration(DateTime startDate, DateDifference duration)
|
||||||
{
|
{
|
||||||
auto currentCalendarSystem = m_calendar->GetCalendarSystem();
|
auto currentCalendarSystem = m_calendar->GetCalendarSystem();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
m_calendar->SetDateTime(startDate);
|
m_calendar->SetDateTime(startDate);
|
||||||
@ -50,7 +54,8 @@ bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const Date
|
|||||||
m_calendar->AddDays(duration.day);
|
m_calendar->AddDays(duration.day);
|
||||||
}
|
}
|
||||||
|
|
||||||
*endDate = m_calendar->GetDateTime();
|
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
||||||
|
return m_calendar->GetDateTime();
|
||||||
}
|
}
|
||||||
catch (Platform::InvalidArgumentException ^ ex)
|
catch (Platform::InvalidArgumentException ^ ex)
|
||||||
{
|
{
|
||||||
@ -58,17 +63,13 @@ bool DateCalculationEngine::AddDuration(_In_ DateTime startDate, _In_ const Date
|
|||||||
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
||||||
|
|
||||||
// Do nothing
|
// Do nothing
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Subtracting Duration from a Date
|
// Subtracting Duration from a Date
|
||||||
// Returns: True if function succeeds to calculate the date else returns False
|
// Returns: True if function succeeds to calculate the date else returns False
|
||||||
bool DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ const DateDifference& duration, _Out_ DateTime* endDate)
|
IBox<DateTime> ^ DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ DateDifference duration)
|
||||||
{
|
{
|
||||||
auto currentCalendarSystem = m_calendar->GetCalendarSystem();
|
auto currentCalendarSystem = m_calendar->GetCalendarSystem();
|
||||||
|
|
||||||
@ -101,7 +102,18 @@ bool DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ const
|
|||||||
{
|
{
|
||||||
m_calendar->AddYears(-duration.year);
|
m_calendar->AddYears(-duration.year);
|
||||||
}
|
}
|
||||||
*endDate = m_calendar->GetDateTime();
|
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
||||||
|
|
||||||
|
auto dateTime = m_calendar->GetDateTime();
|
||||||
|
// Check that the UniversalTime value is not negative
|
||||||
|
if (dateTime.UniversalTime >= 0)
|
||||||
|
{
|
||||||
|
return dateTime;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Platform::InvalidArgumentException ^ ex)
|
catch (Platform::InvalidArgumentException ^ ex)
|
||||||
{
|
{
|
||||||
@ -109,17 +121,12 @@ bool DateCalculationEngine::SubtractDuration(_In_ DateTime startDate, _In_ const
|
|||||||
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
||||||
|
|
||||||
// Do nothing
|
// Do nothing
|
||||||
return false;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
|
||||||
|
|
||||||
// Check that the UniversalTime value is not negative
|
|
||||||
return (endDate->UniversalTime >= 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Calculate the difference between two dates
|
// Calculate the difference between two dates
|
||||||
bool DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateTime date2, _In_ DateUnit outputFormat, _Out_ DateDifference* difference)
|
IBox<DateDifference> ^ DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateTime date2, _In_ DateUnit outputFormat)
|
||||||
{
|
{
|
||||||
DateTime startDate;
|
DateTime startDate;
|
||||||
DateTime endDate;
|
DateTime endDate;
|
||||||
@ -177,8 +184,7 @@ bool DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateT
|
|||||||
{
|
{
|
||||||
// Operation failed due to out of bound result
|
// Operation failed due to out of bound result
|
||||||
// For example: 31st Dec, 9999 - last valid date
|
// For example: 31st Dec, 9999 - last valid date
|
||||||
*difference = DateDifferenceUnknown;
|
return nullptr;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -194,8 +200,7 @@ bool DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateT
|
|||||||
if (differenceInDates[unitIndex] == 0)
|
if (differenceInDates[unitIndex] == 0)
|
||||||
{
|
{
|
||||||
// differenceInDates[unitIndex] is unsigned, the value can't be negative
|
// differenceInDates[unitIndex] is unsigned, the value can't be negative
|
||||||
*difference = DateDifferenceUnknown;
|
return nullptr;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
differenceInDates[unitIndex] -= 1;
|
differenceInDates[unitIndex] -= 1;
|
||||||
pivotDate = tempPivotDate;
|
pivotDate = tempPivotDate;
|
||||||
@ -220,8 +225,7 @@ bool DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateT
|
|||||||
{
|
{
|
||||||
// Operation failed due to out of bound result
|
// Operation failed due to out of bound result
|
||||||
// For example: 31st Dec, 9999 - last valid date
|
// For example: 31st Dec, 9999 - last valid date
|
||||||
*difference = DateDifferenceUnknown;
|
return nullptr;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (tempDaysDiff != 0); // dates are the same - exit the loop
|
} while (tempDaysDiff != 0); // dates are the same - exit the loop
|
||||||
@ -232,8 +236,7 @@ bool DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateT
|
|||||||
if (signedDaysDiff < 0)
|
if (signedDaysDiff < 0)
|
||||||
{
|
{
|
||||||
// daysDiff is unsigned, the value can't be negative
|
// daysDiff is unsigned, the value can't be negative
|
||||||
*difference = DateDifferenceUnknown;
|
return nullptr;
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
daysDiff = signedDaysDiff;
|
daysDiff = signedDaysDiff;
|
||||||
@ -244,11 +247,12 @@ bool DateCalculationEngine::TryGetDateDifference(_In_ DateTime date1, _In_ DateT
|
|||||||
|
|
||||||
differenceInDates[3] = daysDiff;
|
differenceInDates[3] = daysDiff;
|
||||||
|
|
||||||
difference->year = differenceInDates[0];
|
DateDifference result;
|
||||||
difference->month = differenceInDates[1];
|
result.year = differenceInDates[0];
|
||||||
difference->week = differenceInDates[2];
|
result.month = differenceInDates[1];
|
||||||
difference->day = differenceInDates[3];
|
result.week = differenceInDates[2];
|
||||||
return true;
|
result.day = differenceInDates[3];
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Private Methods
|
// Private Methods
|
||||||
|
@ -29,39 +29,30 @@ namespace CalculatorApp
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Struct to store the difference between two Dates in the form of Years, Months , Weeks
|
// Struct to store the difference between two Dates in the form of Years, Months , Weeks
|
||||||
struct DateDifference
|
public
|
||||||
|
value struct DateDifference
|
||||||
{
|
{
|
||||||
int year = 0;
|
int year;
|
||||||
int month = 0;
|
int month;
|
||||||
int week = 0;
|
int week;
|
||||||
int day = 0;
|
int day;
|
||||||
|
|
||||||
bool operator==(const DateDifference& dd) const
|
|
||||||
{
|
|
||||||
return year == dd.year && month == dd.month && week == dd.week && day == dd.day;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const DateDifference DateDifferenceUnknown{ INT_MIN, INT_MIN, INT_MIN, INT_MIN };
|
const DateDifference DateDifferenceUnknown{ INT_MIN, INT_MIN, INT_MIN, INT_MIN };
|
||||||
|
|
||||||
class DateCalculationEngine
|
public
|
||||||
|
ref class DateCalculationEngine sealed
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Constructor
|
// Constructor
|
||||||
DateCalculationEngine(_In_ Platform::String ^ calendarIdentifier);
|
DateCalculationEngine(_In_ Platform::String ^ calendarIdentifier);
|
||||||
|
|
||||||
// Public Methods
|
// Public Methods
|
||||||
bool __nothrow
|
|
||||||
AddDuration(_In_ Windows::Foundation::DateTime startDate, _In_ const DateDifference& duration, _Out_ Windows::Foundation::DateTime* endDate);
|
Platform::IBox<Windows::Foundation::DateTime> ^ AddDuration(_In_ Windows::Foundation::DateTime startDate, _In_ DateDifference duration);
|
||||||
bool __nothrow SubtractDuration(
|
Platform::IBox<Windows::Foundation::DateTime> ^ SubtractDuration(_In_ Windows::Foundation::DateTime startDate, _In_ DateDifference duration);
|
||||||
_In_ Windows::Foundation::DateTime startDate,
|
Platform::IBox<
|
||||||
_In_ const DateDifference& duration,
|
DateDifference> ^ TryGetDateDifference(_In_ Windows::Foundation::DateTime date1, _In_ Windows::Foundation::DateTime date2, _In_ DateUnit outputFormat);
|
||||||
_Out_ Windows::Foundation::DateTime* endDate);
|
|
||||||
bool __nothrow TryGetDateDifference(
|
|
||||||
_In_ Windows::Foundation::DateTime date1,
|
|
||||||
_In_ Windows::Foundation::DateTime date2,
|
|
||||||
_In_ DateUnit outputFormat,
|
|
||||||
_Out_ DateDifference* difference);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Private Variables
|
// Private Variables
|
||||||
@ -76,3 +67,5 @@ namespace CalculatorApp
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool operator==(const CalculatorApp::Common::DateCalculation::DateDifference& l, const CalculatorApp::Common::DateCalculation::DateDifference& r);
|
||||||
|
@ -45,13 +45,13 @@ DateCalculatorViewModel::DateCalculatorViewModel()
|
|||||||
, m_StrDateResult(L"")
|
, m_StrDateResult(L"")
|
||||||
, m_StrDateResultAutomationName(L"")
|
, m_StrDateResultAutomationName(L"")
|
||||||
{
|
{
|
||||||
const auto& localizationSettings = LocalizationSettings::GetInstance();
|
const auto & localizationSettings = LocalizationSettings::GetInstance();
|
||||||
|
|
||||||
// Initialize Date Output format instances
|
// Initialize Date Output format instances
|
||||||
InitializeDateOutputFormats(localizationSettings.GetCalendarIdentifier());
|
InitializeDateOutputFormats(localizationSettings.GetCalendarIdentifier());
|
||||||
|
|
||||||
// Initialize Date Calc engine
|
// Initialize Date Calc engine
|
||||||
m_dateCalcEngine = make_shared<DateCalculationEngine>(localizationSettings.GetCalendarIdentifier());
|
m_dateCalcEngine = ref new DateCalculationEngine(localizationSettings.GetCalendarIdentifier());
|
||||||
// Initialize dates of DatePicker controls to today's date
|
// Initialize dates of DatePicker controls to today's date
|
||||||
auto calendar = ref new Calendar();
|
auto calendar = ref new Calendar();
|
||||||
// We force the timezone to UTC, in order to avoid being affected by Daylight Saving Time
|
// We force the timezone to UTC, in order to avoid being affected by Daylight Saving Time
|
||||||
@ -111,20 +111,20 @@ void DateCalculatorViewModel::OnPropertyChanged(_In_ String ^ prop)
|
|||||||
|
|
||||||
void DateCalculatorViewModel::OnInputsChanged()
|
void DateCalculatorViewModel::OnInputsChanged()
|
||||||
{
|
{
|
||||||
DateDifference dateDiff;
|
|
||||||
|
|
||||||
if (m_IsDateDiffMode)
|
if (m_IsDateDiffMode)
|
||||||
{
|
{
|
||||||
DateTime clippedFromDate = ClipTime(FromDate, true);
|
DateTime clippedFromDate = ClipTime(FromDate, true);
|
||||||
DateTime clippedToDate = ClipTime(ToDate, true);
|
DateTime clippedToDate = ClipTime(ToDate, true);
|
||||||
|
|
||||||
// Calculate difference between two dates
|
// Calculate difference between two dates
|
||||||
if (m_dateCalcEngine->TryGetDateDifference(clippedFromDate, clippedToDate, m_daysOutputFormat, &dateDiff))
|
auto dateDiff = m_dateCalcEngine->TryGetDateDifference(clippedFromDate, clippedToDate, m_daysOutputFormat);
|
||||||
|
if (dateDiff != nullptr)
|
||||||
{
|
{
|
||||||
DateDiffResultInDays = dateDiff;
|
DateDiffResultInDays = dateDiff->Value;
|
||||||
if (m_dateCalcEngine->TryGetDateDifference(clippedFromDate, clippedToDate, m_allDateUnitsOutputFormat, &dateDiff))
|
dateDiff = m_dateCalcEngine->TryGetDateDifference(clippedFromDate, clippedToDate, m_allDateUnitsOutputFormat);
|
||||||
|
if (dateDiff != nullptr)
|
||||||
{
|
{
|
||||||
DateDiffResult = dateDiff;
|
DateDiffResult = dateDiff->Value;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -140,26 +140,28 @@ void DateCalculatorViewModel::OnInputsChanged()
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
DateDifference dateDiff;
|
||||||
dateDiff.day = DaysOffset;
|
dateDiff.day = DaysOffset;
|
||||||
dateDiff.month = MonthsOffset;
|
dateDiff.month = MonthsOffset;
|
||||||
dateDiff.year = YearsOffset;
|
dateDiff.year = YearsOffset;
|
||||||
|
|
||||||
DateTime dateTimeResult;
|
IBox<DateTime> ^ dateTimeResult;
|
||||||
|
|
||||||
if (m_IsAddMode)
|
if (m_IsAddMode)
|
||||||
{
|
{
|
||||||
// Add number of Days, Months and Years to a Date
|
// Add number of Days, Months and Years to a Date
|
||||||
IsOutOfBound = !m_dateCalcEngine->AddDuration(StartDate, dateDiff, &dateTimeResult);
|
dateTimeResult = m_dateCalcEngine->AddDuration(StartDate, dateDiff);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Subtract number of Days, Months and Years from a Date
|
// Subtract number of Days, Months and Years from a Date
|
||||||
IsOutOfBound = !m_dateCalcEngine->SubtractDuration(StartDate, dateDiff, &dateTimeResult);
|
dateTimeResult = m_dateCalcEngine->SubtractDuration(StartDate, dateDiff);
|
||||||
}
|
}
|
||||||
|
IsOutOfBound = dateTimeResult == nullptr;
|
||||||
|
|
||||||
if (!m_isOutOfBound)
|
if (!m_isOutOfBound)
|
||||||
{
|
{
|
||||||
DateResult = dateTimeResult;
|
DateResult = dateTimeResult->Value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -181,8 +183,7 @@ void DateCalculatorViewModel::UpdateDisplayResult()
|
|||||||
StrDateDiffResultInDays = L"";
|
StrDateDiffResultInDays = L"";
|
||||||
StrDateDiffResult = AppResourceProvider::GetInstance()->GetResourceString(L"Date_SameDates");
|
StrDateDiffResult = AppResourceProvider::GetInstance()->GetResourceString(L"Date_SameDates");
|
||||||
}
|
}
|
||||||
else if (m_dateDiffResult == DateDifferenceUnknown ||
|
else if (m_dateDiffResult == DateDifferenceUnknown || (m_dateDiffResult.year == 0 && m_dateDiffResult.month == 0 && m_dateDiffResult.week == 0))
|
||||||
(m_dateDiffResult.year == 0 && m_dateDiffResult.month == 0 && m_dateDiffResult.week == 0))
|
|
||||||
{
|
{
|
||||||
IsDiffInDays = true;
|
IsDiffInDays = true;
|
||||||
StrDateDiffResultInDays = L"";
|
StrDateDiffResultInDays = L"";
|
||||||
|
@ -176,7 +176,7 @@ namespace CalculatorApp
|
|||||||
CalculatorApp::Common::DateCalculation::DateDifference m_dateDiffResultInDays;
|
CalculatorApp::Common::DateCalculation::DateDifference m_dateDiffResultInDays;
|
||||||
|
|
||||||
// Private members
|
// Private members
|
||||||
std::shared_ptr<CalculatorApp::Common::DateCalculation::DateCalculationEngine> m_dateCalcEngine;
|
CalculatorApp::Common::DateCalculation::DateCalculationEngine ^ m_dateCalcEngine;
|
||||||
CalculatorApp::Common::DateCalculation::DateUnit m_daysOutputFormat;
|
CalculatorApp::Common::DateCalculation::DateUnit m_daysOutputFormat;
|
||||||
CalculatorApp::Common::DateCalculation::DateUnit m_allDateUnitsOutputFormat;
|
CalculatorApp::Common::DateCalculation::DateUnit m_allDateUnitsOutputFormat;
|
||||||
Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ m_dateTimeFormatter;
|
Windows::Globalization::DateTimeFormatting::DateTimeFormatter ^ m_dateTimeFormatter;
|
||||||
|
@ -27,8 +27,6 @@ namespace DateCalculationUnitTests
|
|||||||
const int c_subtractCases = 3;
|
const int c_subtractCases = 3;
|
||||||
const int c_dateDiff = 14;
|
const int c_dateDiff = 14;
|
||||||
|
|
||||||
DateCalculationEngine m_DateCalcEngine(CalendarIdentifiers::Gregorian);
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
SYSTEMTIME startDate;
|
SYSTEMTIME startDate;
|
||||||
@ -45,10 +43,20 @@ namespace DateCalculationUnitTests
|
|||||||
DateTimeTestCase datetimeSubtractCase[c_subtractCases];
|
DateTimeTestCase datetimeSubtractCase[c_subtractCases];
|
||||||
|
|
||||||
// Test Class
|
// Test Class
|
||||||
TEST_CLASS(DateCalculatorUnitTests){ public: TEST_CLASS_INITIALIZE(TestClassSetup){ /* Test Case Data */
|
TEST_CLASS(DateCalculatorUnitTests)
|
||||||
|
{
|
||||||
|
static DateCalculationEngine ^ m_DateCalcEngine;
|
||||||
|
|
||||||
// Dates - DD.MM.YYYY
|
public:
|
||||||
/*31.12.9999*/ date[0].wYear = 9999;
|
TEST_CLASS_INITIALIZE(TestClassSetup)
|
||||||
|
{
|
||||||
|
m_DateCalcEngine = ref new DateCalculationEngine(CalendarIdentifiers::Gregorian);
|
||||||
|
|
||||||
|
/* Test Case Data */
|
||||||
|
|
||||||
|
// Dates - DD.MM.YYYY
|
||||||
|
/*31.12.9999*/
|
||||||
|
date[0].wYear = 9999;
|
||||||
date[0].wMonth = 12;
|
date[0].wMonth = 12;
|
||||||
date[0].wDayOfWeek = 5;
|
date[0].wDayOfWeek = 5;
|
||||||
date[0].wDay = 31;
|
date[0].wDay = 31;
|
||||||
@ -300,7 +308,7 @@ TEST_METHOD(TestDateDiff)
|
|||||||
// }
|
// }
|
||||||
|
|
||||||
// // Calculate the difference
|
// // Calculate the difference
|
||||||
// m_DateCalcEngine.TryGetDateDifference(DateUtils::SystemTimeToDateTime(datetimeDifftest[testIndex].startDate),
|
// m_DateCalcEngine->TryGetDateDifference(DateUtils::SystemTimeToDateTime(datetimeDifftest[testIndex].startDate),
|
||||||
// DateUtils::SystemTimeToDateTime(datetimeDifftest[testIndex].endDate), dateOutputFormat, &diff);
|
// DateUtils::SystemTimeToDateTime(datetimeDifftest[testIndex].endDate), dateOutputFormat, &diff);
|
||||||
|
|
||||||
// // Assert for the result
|
// // Assert for the result
|
||||||
@ -327,7 +335,7 @@ TEST_METHOD(TestAddOob)
|
|||||||
// DateTime endDate;
|
// DateTime endDate;
|
||||||
|
|
||||||
// // Add Duration
|
// // Add Duration
|
||||||
// bool isValid = m_DateCalcEngine.AddDuration(DateUtils::SystemTimeToDateTime(datetimeBoundAdd[testIndex].startDate),
|
// bool isValid = m_DateCalcEngine->AddDuration(DateUtils::SystemTimeToDateTime(datetimeBoundAdd[testIndex].startDate),
|
||||||
// datetimeBoundAdd[testIndex].dateDiff, &endDate);
|
// datetimeBoundAdd[testIndex].dateDiff, &endDate);
|
||||||
|
|
||||||
// // Assert for the result
|
// // Assert for the result
|
||||||
@ -340,14 +348,12 @@ TEST_METHOD(TestSubtractOob)
|
|||||||
{
|
{
|
||||||
for (int testIndex = 0; testIndex < c_numSubtractOobDate; testIndex++)
|
for (int testIndex = 0; testIndex < c_numSubtractOobDate; testIndex++)
|
||||||
{
|
{
|
||||||
DateTime endDate;
|
|
||||||
|
|
||||||
// Subtract Duration
|
// Subtract Duration
|
||||||
bool isValid = m_DateCalcEngine.SubtractDuration(
|
auto endDate = m_DateCalcEngine->SubtractDuration(
|
||||||
DateUtils::SystemTimeToDateTime(datetimeBoundSubtract[testIndex].startDate), datetimeBoundSubtract[testIndex].dateDiff, &endDate);
|
DateUtils::SystemTimeToDateTime(datetimeBoundSubtract[testIndex].startDate), datetimeBoundSubtract[testIndex].dateDiff);
|
||||||
|
|
||||||
// Assert for the result
|
// Assert for the result
|
||||||
VERIFY_IS_FALSE(isValid);
|
VERIFY_IS_NULL(endDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -361,7 +367,7 @@ TEST_METHOD(TestAddition)
|
|||||||
// DateTime endDate;
|
// DateTime endDate;
|
||||||
|
|
||||||
// // Add Duration
|
// // Add Duration
|
||||||
// bool isValid = m_DateCalcEngine.AddDuration(DateUtils::SystemTimeToDateTime(datetimeAddCase[testIndex].startDate),
|
// bool isValid = m_DateCalcEngine->AddDuration(DateUtils::SystemTimeToDateTime(datetimeAddCase[testIndex].startDate),
|
||||||
// datetimeAddCase[testIndex].dateDiff, &endDate);
|
// datetimeAddCase[testIndex].dateDiff, &endDate);
|
||||||
|
|
||||||
// // Assert for the result
|
// // Assert for the result
|
||||||
@ -390,7 +396,7 @@ TEST_METHOD(TestSubtraction)
|
|||||||
// DateTime endDate;
|
// DateTime endDate;
|
||||||
|
|
||||||
// // Subtract Duration
|
// // Subtract Duration
|
||||||
// bool isValid = m_DateCalcEngine.SubtractDuration(DateUtils::SystemTimeToDateTime(datetimeSubtractCase[testIndex].startDate),
|
// bool isValid = m_DateCalcEngine->SubtractDuration(DateUtils::SystemTimeToDateTime(datetimeSubtractCase[testIndex].startDate),
|
||||||
// datetimeSubtractCase[testIndex].dateDiff, &endDate);
|
// datetimeSubtractCase[testIndex].dateDiff, &endDate);
|
||||||
|
|
||||||
// // assert for the result
|
// // assert for the result
|
||||||
@ -408,13 +414,9 @@ TEST_METHOD(TestSubtraction)
|
|||||||
// VERIFY_IS_TRUE(isValid);
|
// VERIFY_IS_TRUE(isValid);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
};
|
||||||
private:
|
|
||||||
}
|
|
||||||
;
|
|
||||||
|
|
||||||
TEST_CLASS(DateCalculatorViewModelTests){ public: TEST_CLASS_INITIALIZE(TestClassSetup){ /* Test Case Data */
|
TEST_CLASS(DateCalculatorViewModelTests){ public: TEST_CLASS_INITIALIZE(TestClassSetup){ /* Test Case Data */
|
||||||
|
|
||||||
// Dates - DD.MM.YYYY
|
// Dates - DD.MM.YYYY
|
||||||
/*31.12.9999*/ date[0].wYear = 9999;
|
/*31.12.9999*/ date[0].wYear = 9999;
|
||||||
date[0].wMonth = 12;
|
date[0].wMonth = 12;
|
||||||
@ -683,7 +685,6 @@ TEST_METHOD(DateCalcViewModelAddSubtractInitTest)
|
|||||||
TEST_METHOD(DateCalcViewModelDateDiffDaylightSavingTimeTest)
|
TEST_METHOD(DateCalcViewModelDateDiffDaylightSavingTimeTest)
|
||||||
{
|
{
|
||||||
auto viewModel = ref new DateCalculatorViewModel();
|
auto viewModel = ref new DateCalculatorViewModel();
|
||||||
|
|
||||||
viewModel->IsDateDiffMode = true;
|
viewModel->IsDateDiffMode = true;
|
||||||
VERIFY_IS_TRUE(viewModel->IsDateDiffMode);
|
VERIFY_IS_TRUE(viewModel->IsDateDiffMode);
|
||||||
|
|
||||||
@ -922,8 +923,6 @@ TEST_METHOD(DateCalcViewModelDateDiffFromDateHigherThanToDate)
|
|||||||
// contains the DayOfWeek, Day, Month, and Year
|
// contains the DayOfWeek, Day, Month, and Year
|
||||||
TEST_METHOD(DateCalcViewModelAddSubtractResultAutomationNameTest)
|
TEST_METHOD(DateCalcViewModelAddSubtractResultAutomationNameTest)
|
||||||
{
|
{
|
||||||
auto viewModel = ref new DateCalculatorViewModel();
|
|
||||||
|
|
||||||
auto cal = ref new Calendar();
|
auto cal = ref new Calendar();
|
||||||
cal->Year = 2007;
|
cal->Year = 2007;
|
||||||
cal->Month = 5;
|
cal->Month = 5;
|
||||||
@ -934,6 +933,8 @@ TEST_METHOD(DateCalcViewModelAddSubtractResultAutomationNameTest)
|
|||||||
cal->Second = 0;
|
cal->Second = 0;
|
||||||
|
|
||||||
DateTime startDate = cal->GetDateTime();
|
DateTime startDate = cal->GetDateTime();
|
||||||
|
auto viewModel = ref new DateCalculatorViewModel();
|
||||||
|
|
||||||
viewModel->StartDate = startDate;
|
viewModel->StartDate = startDate;
|
||||||
|
|
||||||
viewModel->IsDateDiffMode = false;
|
viewModel->IsDateDiffMode = false;
|
||||||
@ -955,7 +956,7 @@ TEST_METHOD(DateCalcViewModelAddSubtractResultAutomationNameTest)
|
|||||||
|
|
||||||
TEST_METHOD(JaEraTransitionAddition)
|
TEST_METHOD(JaEraTransitionAddition)
|
||||||
{
|
{
|
||||||
auto viewModel = make_unique<DateCalculationEngine>(CalendarIdentifiers::Japanese);
|
auto engine = ref new DateCalculationEngine(CalendarIdentifiers::Japanese);
|
||||||
auto cal = ref new Calendar();
|
auto cal = ref new Calendar();
|
||||||
|
|
||||||
// The Showa period ended in Jan 1989.
|
// The Showa period ended in Jan 1989.
|
||||||
@ -973,10 +974,9 @@ TEST_METHOD(JaEraTransitionAddition)
|
|||||||
DateDifference yearDuration;
|
DateDifference yearDuration;
|
||||||
yearDuration.year = 1;
|
yearDuration.year = 1;
|
||||||
|
|
||||||
DateTime actualYearResult;
|
auto actualYearResult = engine->AddDuration(startTime, yearDuration);
|
||||||
viewModel->AddDuration(startTime, yearDuration, &actualYearResult);
|
|
||||||
|
|
||||||
VERIFY_ARE_EQUAL(expectedYearResult.UniversalTime, actualYearResult.UniversalTime);
|
VERIFY_ARE_EQUAL(expectedYearResult.UniversalTime, actualYearResult->Value.UniversalTime);
|
||||||
|
|
||||||
cal->Year = 1989;
|
cal->Year = 1989;
|
||||||
cal->Month = 2;
|
cal->Month = 2;
|
||||||
@ -987,15 +987,14 @@ TEST_METHOD(JaEraTransitionAddition)
|
|||||||
DateDifference monthDuration;
|
DateDifference monthDuration;
|
||||||
monthDuration.month = 1;
|
monthDuration.month = 1;
|
||||||
|
|
||||||
DateTime actualMonthResult;
|
auto actualMonthResult = engine->AddDuration(startTime, monthDuration);
|
||||||
viewModel->AddDuration(startTime, monthDuration, &actualMonthResult);
|
|
||||||
|
|
||||||
VERIFY_ARE_EQUAL(expectedMonthResult.UniversalTime, actualMonthResult.UniversalTime);
|
VERIFY_ARE_EQUAL(expectedMonthResult.UniversalTime, actualMonthResult->Value.UniversalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(JaEraTransitionSubtraction)
|
TEST_METHOD(JaEraTransitionSubtraction)
|
||||||
{
|
{
|
||||||
auto viewModel = make_unique<DateCalculationEngine>(CalendarIdentifiers::Japanese);
|
auto engine = ref new DateCalculationEngine(CalendarIdentifiers::Japanese);
|
||||||
auto cal = ref new Calendar();
|
auto cal = ref new Calendar();
|
||||||
|
|
||||||
// The Showa period ended in Jan 1989.
|
// The Showa period ended in Jan 1989.
|
||||||
@ -1013,10 +1012,9 @@ TEST_METHOD(JaEraTransitionSubtraction)
|
|||||||
DateDifference yearDuration;
|
DateDifference yearDuration;
|
||||||
yearDuration.year = 1;
|
yearDuration.year = 1;
|
||||||
|
|
||||||
DateTime actualYearResult;
|
auto actualYearResult = engine->SubtractDuration(startTime, yearDuration);
|
||||||
viewModel->SubtractDuration(startTime, yearDuration, &actualYearResult);
|
|
||||||
|
|
||||||
VERIFY_ARE_EQUAL(expectedYearResult.UniversalTime, actualYearResult.UniversalTime);
|
VERIFY_ARE_EQUAL(expectedYearResult.UniversalTime, actualYearResult->Value.UniversalTime);
|
||||||
|
|
||||||
cal->Year = 1989;
|
cal->Year = 1989;
|
||||||
cal->Month = 1;
|
cal->Month = 1;
|
||||||
@ -1027,15 +1025,14 @@ TEST_METHOD(JaEraTransitionSubtraction)
|
|||||||
DateDifference monthDuration;
|
DateDifference monthDuration;
|
||||||
monthDuration.month = 1;
|
monthDuration.month = 1;
|
||||||
|
|
||||||
DateTime actualMonthResult;
|
auto actualMonthResult = engine->SubtractDuration(startTime, monthDuration);
|
||||||
viewModel->SubtractDuration(startTime, monthDuration, &actualMonthResult);
|
|
||||||
|
|
||||||
VERIFY_ARE_EQUAL(expectedMonthResult.UniversalTime, actualMonthResult.UniversalTime);
|
VERIFY_ARE_EQUAL(expectedMonthResult.UniversalTime, actualMonthResult->Value.UniversalTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_METHOD(JaEraTransitionDifference)
|
TEST_METHOD(JaEraTransitionDifference)
|
||||||
{
|
{
|
||||||
auto viewModel = make_unique<DateCalculationEngine>(CalendarIdentifiers::Japanese);
|
auto engine = ref new DateCalculationEngine(CalendarIdentifiers::Japanese);
|
||||||
auto cal = ref new Calendar();
|
auto cal = ref new Calendar();
|
||||||
|
|
||||||
// The Showa period ended in Jan 8, 1989. Pick 2 days across that boundary
|
// The Showa period ended in Jan 8, 1989. Pick 2 days across that boundary
|
||||||
@ -1049,10 +1046,12 @@ TEST_METHOD(JaEraTransitionDifference)
|
|||||||
cal->Day = 20;
|
cal->Day = 20;
|
||||||
auto endTime = cal->GetDateTime();
|
auto endTime = cal->GetDateTime();
|
||||||
|
|
||||||
DateDifference diff;
|
auto diff = engine->TryGetDateDifference(startTime, endTime, DateUnit::Day);
|
||||||
VERIFY_IS_TRUE(viewModel->TryGetDateDifference(startTime, endTime, DateUnit::Day, &diff));
|
VERIFY_IS_NOT_NULL(diff);
|
||||||
VERIFY_ARE_EQUAL(diff.day, 19);
|
VERIFY_ARE_EQUAL(diff->Value.day, 19);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
|
DateCalculationEngine ^ DateCalculatorUnitTests::m_DateCalcEngine;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user