mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-20 11:48:30 -06:00
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:
parent
399573a89d
commit
7183e7c43a
@ -81,6 +81,13 @@ GncOptionDateValue::get_value() const
|
||||
struct tm now{static_cast<tm>(GncDateTime())};
|
||||
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 ||
|
||||
m_period == RelativeDatePeriod::PREV_YEAR)
|
||||
{
|
||||
@ -91,7 +98,9 @@ GncOptionDateValue::get_value() const
|
||||
else if (m_period == RelativeDatePeriod::PREV_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)
|
||||
now.tm_mon -= 3;
|
||||
if (m_type == DateType::ENDING)
|
||||
|
Loading…
Reference in New Issue
Block a user