Moved all the Japanese Era logic inside the Year case of the switch statement
This commit is contained in:
parent
1bd4f1870c
commit
2fc8196104
@ -273,31 +273,33 @@ bool DateCalculationEngine::TryGetCalendarDaysInYear(_In_ DateTime date, _Out_ U
|
|||||||
// Adds/Subtracts certain value for a particular date unit
|
// Adds/Subtracts certain value for a particular date unit
|
||||||
DateTime DateCalculationEngine::AdjustCalendarDate(Windows::Foundation::DateTime date, DateUnit dateUnit, int difference)
|
DateTime DateCalculationEngine::AdjustCalendarDate(Windows::Foundation::DateTime date, DateUnit dateUnit, int difference)
|
||||||
{
|
{
|
||||||
auto currentCalendarSystem = m_calendar->GetCalendarSystem();
|
|
||||||
|
|
||||||
m_calendar->SetDateTime(date);
|
m_calendar->SetDateTime(date);
|
||||||
|
|
||||||
switch (dateUnit)
|
switch (dateUnit)
|
||||||
{
|
{
|
||||||
case DateUnit::Year:
|
case DateUnit::Year:
|
||||||
// In the Japanese calendar, transition years have 2 partial years.
|
|
||||||
// It is not guaranteed that adding 1 year will always add 365 days in the Japanese Calendar.
|
|
||||||
// To work around this quirk, we will change the calendar system to Gregorian before adding 1 year in the Japanese Calendar case only.
|
|
||||||
// We will then return the calendar system back to the Japanese Calendar.
|
|
||||||
if (currentCalendarSystem == CalendarIdentifiers::Japanese)
|
|
||||||
{
|
{
|
||||||
m_calendar->ChangeCalendarSystem(CalendarIdentifiers::Gregorian);
|
// In the Japanese calendar, transition years have 2 partial years.
|
||||||
}
|
// It is not guaranteed that adding 1 year will always add 365 days in the Japanese Calendar.
|
||||||
|
// To work around this quirk, we will change the calendar system to Gregorian before adding 1 year in the Japanese Calendar case only.
|
||||||
|
// We will then return the calendar system back to the Japanese Calendar.
|
||||||
|
auto currentCalendarSystem = m_calendar->GetCalendarSystem();
|
||||||
|
if (currentCalendarSystem == CalendarIdentifiers::Japanese)
|
||||||
|
{
|
||||||
|
m_calendar->ChangeCalendarSystem(CalendarIdentifiers::Gregorian);
|
||||||
|
}
|
||||||
|
|
||||||
m_calendar->AddYears(difference);
|
m_calendar->AddYears(difference);
|
||||||
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
m_calendar->ChangeCalendarSystem(currentCalendarSystem);
|
||||||
break;
|
break;
|
||||||
case DateUnit::Month:
|
}
|
||||||
m_calendar->AddMonths(difference);
|
case DateUnit::Month:
|
||||||
break;
|
m_calendar->AddMonths(difference);
|
||||||
case DateUnit::Week:
|
break;
|
||||||
m_calendar->AddWeeks(difference);
|
case DateUnit::Week:
|
||||||
break;
|
m_calendar->AddWeeks(difference);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_calendar->GetDateTime();
|
return m_calendar->GetDateTime();
|
||||||
|
Loading…
Reference in New Issue
Block a user