Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sap.ui.core.format.DateFormat format for 31.12.2018 is not correct in German language #2370

Closed
strawherotk opened this issue Jan 15, 2019 · 3 comments

Comments

@strawherotk
Copy link

strawherotk commented Jan 15, 2019

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:

  1. Create a date using: Date(2018,11,31) (date: 31.12.2018 in German)
    var oDate = new Date(2018,11,31);

  2. Create a format instance from sap.ui.core:

var sFromatedDate = sap.ui.core.format.DateFormat.getDateInstance({
                    pattern: "dd.MM.YYYY"
                }).format(oDate);
  1. Get the formatted date in local language:
    sFromatedDate

What is the expected result?
sFromatedDate should show the formatted date in the local language.
E.g.:

  • German: 31.12.2018
  • English: 31.12.2018

What happens instead?
The formatted date for English is correct.
But for German it is incorrect. The year changed to 2019:
E.g.:

  • German: 31.12.2019
  • English: 31.12.2018

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:
2019-01-15_13h57_27

Code in get week number function: (root cause of the problem here)
2019-01-15_14h05_35

@stephania87
Copy link

Use it with yyyy instead of YYYY, because of the way calendar years are taken by the specific format string

@strawherotk
Copy link
Author

Great. Thanks for the quick support @stephania87
More details explanation for anyone interested:
https://sapui5.hana.ondemand.com/sdk/#/topic/91f2eba36f4d1014b6dd926db0e91070

@stephania87
Copy link

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".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants