GnuCash
Contact   Instructions
Bug 752395 - Start Day of weekly report doesn't respond to change in locale
Summary: Start Day of weekly report doesn't respond to change in locale
Status: ASSIGNED
Alias: None
Product: GnuCash
Classification: Unclassified
Component: Reports (show other bugs)
Version: 2.6.x
Hardware: Other Mac OS
: Normal normal
Target Milestone: ---
Assignee: reports
QA Contact: reports
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2015-07-14 19:46 EDT by Michael Hendry
Modified: 2020-06-01 15:26 EDT (History)
7 users (show)

See Also:


Attachments

Description Michael Hendry 2015-07-14 19:46:46 EDT
Set up a transaction report.

Choose to have weekly subtotals.

Note the day of the week that begins each subtotal (in my case, Monday).

Change the locale from UK (start of week is Monday) to US (start of week is Sunday).

Run the same transaction report - the weekly subtotal still starts on Monday.

Another user has had the converse experience - see the thread on the list at:

http://lists.gnucash.org/pipermail/gnucash-user/2015-June/060793.html

As a further test, I created a new user, set up to use the US locale, installed GnuCash, set up a new account, and ran the transaction report. In this case, the reports still start on Monday.
Comment 1 Adrien 2019-08-13 12:01:47 EDT
I wonder, was the report changed to fix this and not noted in this bug? Because now there is a thread that explains how the report is stuck on Sunday and doesn't take into account locale at all: https://lists.gnucash.org/pipermail/gnucash-user/2019-August/086414.html.
Comment 2 Christopher Lam 2019-08-15 04:10:31 EDT
Ok this is fixed in maint as https://github.com/Gnucash/gnucash/commit/f64dd0860fde4a04d9298b7c37430996fcc73efb -- the next Windows build tomorrow may be used for testing
Comment 3 Christopher Lam 2019-08-18 21:46:51 EDT
Tests show Linux obeys locale correctly. Windows doesn't. Unknown MacOS behaviour.

From bug 795251#c28 - "We've simply disabled C++ localization on Windows."

Could this be the reason Windows ICU getFirstDayOfWeek always returns 1 in Windows?
Comment 4 John Ralls 2019-08-18 23:19:20 EDT
Maybe. Depends on how you're creating the Calendar. Try

   Locale loc(getlocale());
   Calendar cal = Calendar::createInstance(loc);
   int first_day = cal.firstDayOfWeek();

If that fails on Windows it might be because Windows getlocale returns e.g. en-AU instead of en_AU so a little string processing might be required.
Comment 5 Adrien 2019-08-18 23:34:26 EDT
My recent tests on MacOS Mojave all result in Sunday as first day of week on this report. The locale or the first day of week setting doesn't seem to be honored. (I tested with the current release, not maint)
Comment 6 Christopher Lam 2019-08-19 07:17:48 EDT
Reply from a Microsoftie :)
https://sourceforge.net/p/icu/mailman/message/36743464/

Unfortunately I don't have a Windows build environment and cannot comme.t

@Adrien this fix is 2days fresh in maint.

If ICU will query locale in Linux, and Regional Settings in Windows rather than the LANG/LANGUAGE in environment, then it may not be the right approach for GnuCash? Ideally I think need to find a Windows call which obeys MingW's locale? ^ Note I am stringing words together without real understanding of Windows internals.

--->---
Hello,

What version of ICU are you using, and on what version of Windows are you testing?

The initial default locale for ICU (in most cases) should be the same as the NLS User Locale, aka the "Regional Format" in Windows.

(Note that ICU uses CLDR data, so the Windows defaults and the ICU defaults might not match. Additionally, ICU does not pick up on any overridden settings, so if you’ve changed the first day of week setting then it  will not be picked up and you will continue to get the default value).

For example, I get a value of 2 for the locale ru-RU.

Thanks,
Jeff
From: Christopher Lam <christopher.lck@...>
Sent: Sunday, August 18, 2019 4:04 AM
To: icu-support@...
Subject: [icu-support] getFirstDayOfWeek

Hi all
We're attempting to use getFirstDayOfWeek to return 1-7 in current locale; this works well on Linux but doesn't on Windows. Any idea how ICU decides how to retrieve current locale?
Here's snippet: on Linux it returns 1-7 as expected but Windows returns 1 irrespective of current locale, or Windows' regional settings.

    static int cached_result = 0;

    if (!cached_result)
    {
        UErrorCode err = U_ZERO_ERROR;
        auto cal = icu::Calendar::createInstance (err);
        if (!cal)
        {
            PERR("ICU error: %s\n", u_errorName (err));
            return 0;
        }
        /* 1 for sunday, 2 for monday, etc. */
        cached_result = cal->getFirstDayOfWeek (err);
        delete cal;
    }
    return cached_result;
---<---
Comment 7 Christopher Lam 2019-08-20 00:22:45 EDT
I've done some more research.

* guile provides the (ice-9 i18n) which provides low-level access to glibc's nl-langinfo -- it exposes many API calls, some of which may be generally useful to various reports e.g. D_T_FMT may be used to return a date-format string suitable to locale https://www.gnu.org/software/guile/manual/html_node/Accessing-Locale-Information.html#Accessing-Locale-Information

* glibc's nl-langinfo provides access to detailed locale information thus https://www.gnu.org/software/libc/manual/html_mono/libc.html#The-Elegant-and-Fast-Way

The bad news is that although nl_langinfo can accept _NL_TIME_FIRST_WEEKDAY to return 1-7 firstdayofweek -- see https://github.com/bminor/glibc/blob/master/locale/categories.def#L245 -- this is unofficial and https://www.gnu.org/software/libc/manual/html_mono/libc.html#The-Elegant-and-Fast-Way recommends:

 "The file langinfo.h defines a lot more symbols but none of them are official. Using them is not portable, and the format of the return values might change. Therefore we recommended you not use them."

--

ICU seems dedicated to retrieving locale on Unix or Regional Settings on Windows.

So I am not sure there is a portable locale info accessor for now.
Comment 8 Christopher Lam 2019-08-20 05:36:19 EDT
Another API found in Boost.Locale, hopefully will work well on Windows & macOS

https://www.boost.org/doc/libs/1_48_0/libs/locale/doc/html/classboost_1_1locale_1_1calendar.html#a8144b98a316798476040348483fe2a6e

Someone else will have to code in C++ and test it for me :)
Comment 9 Christopher Lam 2019-08-23 19:27:31 EDT
Further comments -- https://sourceforge.net/p/icu/mailman/message/36743464/

--->---
 Sorry if my previous mail was perhaps confusing.

getFirstDayOfWeek does *not* use/seek the Regional Settings for "First Day of Week" at all on Windows.

The value of getFirstDayOfWeek would be based on the ICU/CLDR data for the Windows locale setting, very much like how it would function on POSIX platforms.

​Thanks,
Jeff

 
Hello
Thank you for your reply.
The test ran on Windows 10, and if getFirstDayOfWeek on Windows seeks the Regional Settings, then it may not suit us after all... It's for a Linux app ported to Windows via MingW and we were looking for a cross-platform solution that obeyed POSIX locale. Unfortunately glibc's langinfo does not formally expose  _NL_TIME_FIRST_WEEKDAY.
Thank you anyway for your help!
---<---
Comment 10 Adrien 2019-09-09 13:36:40 EDT
At least on MacOS now, the start day for 'Weekly' on the Transaction Report is Saturday with the locale set to Sunday. (another user noted on gnucash-user that their locale was set to Monday)
Comment 11 Long 2020-02-23 12:24:38 EST
i have the same problems with recurring transactions, transactions report, expense vs day of week... on both Windows 10 and Linux Mint 19.3

Note You need to log in before you can comment on or make changes to this bug.