After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 794030 - relative date functions compute wrong day of month
relative date functions compute wrong day of month
Status: RESOLVED FIXED
Product: GnuCash
Classification: Other
Component: Reports
git-master
Other Linux
: Normal normal
: ---
Assigned To: gnucash-reports-maint
gnucash-reports-maint
Depends on:
Blocks:
 
 
Reported: 2018-03-03 18:57 UTC by Fabian Müller
Modified: 2018-06-30 00:05 UTC
See Also:
GNOME target: ---
GNOME version: ---



Description Fabian Müller 2018-03-03 18:57:27 UTC
The file /src/app-utils/date-utilities.scm contains eight functions by the names of get-{one-month,three-months,six-months,one-year}-{ago,ahead}, which all contain a statement like

(if (> month-days (tm:mday now))
  (set-tm:mday now month-days))

Note that in the first of these functions the variable is called month-length instead of month-days, otherwise they are the same.

The issue is that all these functions should have a "<" instead of ">" in this statement. The condition is meant to prevent the situation where e.g. on May 31, after substracting one month from the date, one would end up with the invalid date "April 31". In these cases, the day-of-month field should be set to the last valid number (so in this case one would end up with "April 30"). This correction should of course occur if the number days in the current month is *less* than the current day-of-month, not more.

I think this issue can be fixed by simply replacing ">" by "<" in these eight places.
Comment 1 Chris 2018-03-11 04:43:57 UTC
Hi Fabian,

These functions are not actually present in any default reports, hence, are not generally used.

Do you have a use case for them, in a private report? If not I'd suggest they just be removed.

In the future we aim to remove date-utilities.scm altogether.
Comment 2 Fabian Müller 2018-03-15 09:09:14 UTC
Hi Chris,

My use case is as follows: I'm running a regular monthly Income & Expenses report that I export to PDF and save at the end of every month. However, my salary always arrives on one of the last days of the month, making the month-to-date I&E report display a net loss on any day before that. I found that switching to a "running month" scheme (i.e., having the report run from "today's date last month" until today) gives me a much better overview to determine at a glance whether I'm over or under budget.

Note that I did not create a custom report for this but instead directly edited the source code of the standard I&E report, which I found easier by far. I am a programmer but not really fluent in scheme, so reading and modifying existing code for me is much easier than writing it from scratch. I imagine this situation is not too uncommon.

My suggestion therefore would be to remove these functions from date-utilities.scm if they are not needed anywhere, but include maybe one of them in hello-world.scm for illustrative purposes, so people like me can copy&paste them from there. What do you think?
Comment 3 Chris 2018-03-16 04:11:59 UTC
Hi Fabian

If you're using these functions then I'd think there's a benefit to fixing them, adding test cases, and even adding them onto the default relative date selectors which will prevent bitrot. The main burden will fall upon the scheme maintainers. I believe the strings have already been translated a long time ago.

What would the devs recommend?
Comment 4 Fabian Müller 2018-03-16 10:35:59 UTC
Hi all,

Just a side remark: While googling this before, I encountered this discussion:

  https://gnucash.uservoice.com/forums/101223-feature-request/suggestions/1569035-add-tomorrow-to-the-list-of-symbolic-dates-for-d

I agree with cstim there that having too many options in the dropdown box could hinder usability. Structuring the dropdown list with optgroup's would help, but I guess that would entail fiddling with the definition of gnc:make-date-option.
Comment 5 Chris 2018-03-25 23:01:20 UTC
fixed (in upcoming 2.6.20 and 2.7.8) but the code is still inaccessible in default reports.
Comment 6 John Ralls 2018-03-25 23:11:58 UTC
Inaccessible or just not used? IOW it's available if someone wants to use it in a default report, right?
Comment 7 Chris 2018-03-26 00:45:30 UTC
JRalls- Correct, they are unused in default reports.
Comment 8 John Ralls 2018-03-26 00:52:44 UTC
So since your PR is merged I'm closing this. Thanks.
Comment 9 John Ralls 2018-06-30 00:05:12 UTC
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=794030. Please update any external references or bookmarks.