mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
[C++options] Fix previous month and previous quarter at the end of March
. Because March has more days than February the previous month offset was getting normalized back to the current month--th 29 February this year is really 1 March, so normalizing before setting the day caused begin/end previous month to return the begin/end of the current month. That probably happened on the 31st of May, July, October, and December as well, I just hadn't managed to test on those days. Switching the normalization to after calculating the day of the month broke the previous quarter calculation because now the month was out of range, so normalize month & year first.
This commit is contained in:
parent
abd1a0b3f1
commit
1fddf70e21
@ -481,7 +481,11 @@ reldate_set_day_and_time(struct tm& now, RelativeDateType type)
|
||||
}
|
||||
else if (type == RelativeDateType::END)
|
||||
{
|
||||
now.tm_mday = gnc_date_get_last_mday(now.tm_mon, now.tm_year + 1900);
|
||||
/* Ensure that the month is between 0 and 12*/
|
||||
auto year_delta = now.tm_mon / 12 + now.tm_mon < 0 ? -1 : 0;
|
||||
auto month = now.tm_mon - 12 * year_delta;
|
||||
auto year = now.tm_year + year_delta + 1900;
|
||||
now.tm_mday = gnc_date_get_last_mday(month, year);
|
||||
gnc_tm_set_day_end(&now);
|
||||
}
|
||||
// Do nothing for LAST and NEXT.
|
||||
@ -559,8 +563,8 @@ gnc_relative_date_to_time64(RelativeDatePeriod period)
|
||||
else if (reldate_is_next(period))
|
||||
now.tm_mday += 7;
|
||||
}
|
||||
normalize_reldate_tm(now);
|
||||
reldate_set_day_and_time(now, checked_reldate(period).m_type);
|
||||
normalize_reldate_tm(now);
|
||||
return static_cast<time64>(GncDateTime(now));
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user