OpenUI5 version:
1.52.9
Browser/version (+device/version):
Desktop/Win 10/Chrome Version 71.0.3578.98
Any other tested browsers/devices(OK/FAIL):
Fail on all other PC & browser.
Steps to reproduce the problem:
var oDate = new Date(2018,11,31);var sFromatedDate = sap.ui.core.format.DateFormat.getDateInstance({
pattern: "dd.MM.YYYY"
}).format(oDate);
sFromatedDate What is the expected result?
sFromatedDate should show the formatted date in the local language.
E.g.:
What happens instead?
The formatted date for English is correct.
But for German it is incorrect. The year changed to 2019:
E.g.:
Any other information? (attach a screenshot if possible)
I've debugged into sap.ui.core.format library's code, and found out that the date 31.12.2018 is calculated (in German) as the _first date of the first week_ of the new year 2019, instead of the last date in 2018. The _getWeekByDate_ function returned an object:
{year: 2019, week: 0}
Which may be correct in German date format somehow. But in our production, it's not correct, since we only show formatted date in dd.mm.yyyy, without the week number.
I will attach the screenshot for debugging code.
You can see the value of variable of the right side of each code line.
(I'm using Chrome's debugger)
_Code in get year function:_

_Code in get week number function: (root cause of the problem here)_

Use it with yyyy instead of YYYY, because of the way calendar years are taken by the specific format string
Great. Thanks for the quick support @stephania87
More details explanation for anyone interested:
https://sapui5.hana.ondemand.com/sdk/#/topic/91f2eba36f4d1014b6dd926db0e91070
Hi,
The more detailed answer I have from the dev team is as follows:
According the Unicode LDML Date Format notation (https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table ) the year format YYYY is corresponding to:
Year in “Week of Year” based calendars in which the year transition occurs on a week boundary; may differ from calendar year ‘y’ near a year transition. This numeric year designation is used in conjunction with pattern character ‘w’ in the ISO year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems where week date processing is desired. The field length is interpreted in the same was as for ‘y’; that is, “yy” specifies use of the two low-order year digits, while any other field length specifies a minimum number of digits to display.
To receive the expected year please replace "YYYY" with "yyyy".
Most helpful comment
Hi,
The more detailed answer I have from the dev team is as follows:
According the Unicode LDML Date Format notation (https://www.unicode.org/reports/tr35/tr35-dates.html#Date_Field_Symbol_Table ) the year format YYYY is corresponding to:
Year in “Week of Year” based calendars in which the year transition occurs on a week boundary; may differ from calendar year ‘y’ near a year transition. This numeric year designation is used in conjunction with pattern character ‘w’ in the ISO year-week calendar as defined by ISO 8601, but can be used in non-Gregorian based calendar systems where week date processing is desired. The field length is interpreted in the same was as for ‘y’; that is, “yy” specifies use of the two low-order year digits, while any other field length specifies a minimum number of digits to display.
To receive the expected year please replace "YYYY" with "yyyy".