Fix begin/end of quarter calculations.

Set the period to the calendar year if it's not set in prefs.
Handle correctly the FY start month being after the current month.
This commit is contained in:
John Ralls 2019-11-10 15:34:21 -08:00
parent 399573a89d
commit 7183e7c43a

View File

@ -81,6 +81,13 @@ GncOptionDateValue::get_value() const
struct tm now{static_cast<tm>(GncDateTime())}; struct tm now{static_cast<tm>(GncDateTime())};
struct tm period{static_cast<tm>(GncDateTime(gnc_accounting_period_fiscal_start()))}; struct tm period{static_cast<tm>(GncDateTime(gnc_accounting_period_fiscal_start()))};
if (period.tm_mon == now.tm_mon && period.tm_mday == now.tm_mday)
{
//No set accounting period, use the calendar year
period.tm_mon = 0;
period.tm_mday = 0;
}
if (m_period == RelativeDatePeriod::CAL_YEAR || if (m_period == RelativeDatePeriod::CAL_YEAR ||
m_period == RelativeDatePeriod::PREV_YEAR) m_period == RelativeDatePeriod::PREV_YEAR)
{ {
@ -91,7 +98,9 @@ GncOptionDateValue::get_value() const
else if (m_period == RelativeDatePeriod::PREV_QUARTER || else if (m_period == RelativeDatePeriod::PREV_QUARTER ||
m_period == RelativeDatePeriod::CURRENT_QUARTER) m_period == RelativeDatePeriod::CURRENT_QUARTER)
{ {
now.tm_mon = now.tm_mon - (now.tm_mon - period.tm_mon) % 3; auto offset = (now.tm_mon > period.tm_mon ? now.tm_mon - period.tm_mon :
period.tm_mon - now.tm_mon) % 3;
now.tm_mon = now.tm_mon - offset;
if (m_period == RelativeDatePeriod::PREV_QUARTER) if (m_period == RelativeDatePeriod::PREV_QUARTER)
now.tm_mon -= 3; now.tm_mon -= 3;
if (m_type == DateType::ENDING) if (m_type == DateType::ENDING)