SAP / ui5-webcomponents

UI5 Web Components - the enterprise-flavored sugar on top of native APIs! Build SAP Fiori user interfaces with the technology of your choice.
https://sap.github.io/ui5-webcomponents/
Apache License 2.0
1.47k stars 254 forks source link

[DatePicker|Calendar components]: Year increments when old Buddhist date is entered #6901

Open allen138 opened 1 year ago

allen138 commented 1 year ago

Bug Description

Hi team,

When the configuration sets Buddhist as the calendarType and the user tries to select an old date either manually or through the calendar picker onChange will cause the year to increment by 2. The incrementation only happens when month is April or Greater and when the Buddhist year is 2484 or less (Gregorian year 1941 or less). This is because before January 1, 1941, the Thai calendar first of the year was actually April 1st. (which is what is explained here, sap/ui/core/date/Buddhist.js#L14-L24. The reason for the incrementation is because every time the date-string is parsed/formatted the value of the year will increment by 1. For the date picker, the parse/formatting will happen during DatePicker.ts#L533?_updateValueAndFireEvents() and DatePicker.ts#L425?onBeforeRendering()

In my opinion, the logic in the date picker/calendar components are correct and the root cause likely lies within src/sap/ui/core/date/Buddhist.js#L82-L85, but the behavior between openUI5 sap.m.DatePicker and the webcomponent is different. Hence, this GH issue.

OpenUI5, only increments by 1 whereas ui5-wc increments by 2.

Open date picker, select a date. OpenUI5 does not increment whereas ui5-wc increments by 2.

For now we can focus on the behavior of the webcomponent.

Affected Component

Date Picker/Calendar Components

Expected Behaviour

Using the Buddhist Thai calendar, the user is able to manually enter a date or select a date through the picker without it being modified under the covers.

Isolated Example

https://codesandbox.io/s/ui5-webcomponents-forked-gm7tuh?file=/index.html

Steps to Reproduce

  1. Open the codesandbox. Enter an old date, e.g. 04/19/2490
  2. Click or tab out to trigger 'onChange'. Notice the value in the input has incremented by 2.
  3. Open the calendar picker, notice the value in the input has incremented by 1, and the year in the month picker is also incremented by 1.
  4. Select a date in the picker and see the value increments again.
  5. For comparison to openUI5's sap.m.DatePicker, you can try this snippix: https://snippix.only.sap/snippets/866084

Log Output, Stack Trace or Screenshots

No response

Priority

None

UI5 Web Components Version

main

Browser

Chrome, Edge, Firefox, Safari

Operating System

No response

Additional Context

No response

Declaration

ivoplashkov commented 1 year ago

Hello colleagues,

The issue is reproduced as described by the reporter:

  1. Go to https://codesandbox.io/s/ui5-webcomponents-forked-gm7tuh?file=/index.html
  2. Select a month April or Greater and Buddhist year 2484 or less (Gregorian year 1941 or less).
  3. You can see that the year in the Input field is incremented by 2.

Could you please have a look?

Thank you in advance! Best regards, Ivaylo