openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

DateFormat.getDateInstance ignores Locale for Week Parsing

Open janmattfeld opened this issue 7 years ago • 2 comments

Trying to get the first date of the first week 2019 with sap.ui.core.format.DateFormat.getDateInstance reports different dates, depending the current browser language. As expected: In the US the first week of a year always starts on January 1st, in Germany the first day of week 01/2019 is Monday, December, 31st (2018).

To get a localized week start, it should be enough to pass the locale manually:

sap.ui.core.format.DateFormat.getDateInstance({
            pattern: "YYYYww",
            UTC: true,
        }, new sap.ui.core.Locale("de_DE")).parse("201901", true)

In an English browser, this still returns January 1st, when it really should be December 31st 2018. What gives the desired result is sap.ui.getCore().getConfiguration().setLanguage("de_DE"). But that seems a bit harsh. Is this a bug?

OpenUI5 version: 1.58.6, 1.61.1 Browser/Version: Chrome 71.0, Firefox 64.0, Edge, all fail

janmattfeld avatar Jan 09 '19 16:01 janmattfeld

Hello @janmattfeld , Thank you for sharing this finding. I've created an internal incident 1970026855. The status of the issue will be updated here in GitHub. Regards, Filip

fifoosid avatar Jan 10 '19 14:01 fifoosid

Hi @janmattfeld,

this works as expected, although I understand it is confusing - the locale used for formatting does not impact the week calculation. Think of an American working in Germany - he wants to see day and month names in English, but the week starts on Monday and week numbering should follow the German system.

Please be aware that for the US, the first week does always start on January 1st, even if this is not the regular first day of week - the first week may just contain a single day.

goligo avatar Jan 22 '19 16:01 goligo