ui5-webcomponents icon indicating copy to clipboard operation
ui5-webcomponents copied to clipboard

min-date and max-date as Date instead of Formatted String

Open ChewbaccaCookie opened this issue 3 years ago • 3 comments

Feature Request Description

It would be nice for date-picker and daterangepicker to have the option to provide the minimum and maximum date as a Date instead of the formatted date string.

It is very troublesome to format the date correctly, especially since the UI5 components use a different date notation than other major libraries (Look for example at dayjs).

Proposed Solution

To have a properties like value and date-value:

  • min-date-value: Minimum date as date object
  • max-date-value: Maximum date as date object

Proposed Alternatives

Other way would be to allow a single formatting independent date format for min-date and max-date, like YYYY-MM-DD.

Priority

  • [ ] Low
  • [x] Medium
  • [ ] High
  • [ ] Very High

Stakeholder Info

  • Organization: SAP

ChewbaccaCookie avatar Jun 29 '22 14:06 ChewbaccaCookie

Hi @SAP/ui5-webcomponents-topic-b, please take a look at this feature request.

georgimkv avatar Jul 13 '22 08:07 georgimkv

Hello @ChewbaccaCookie ,

Have you checked the formatValue method in the DatePicker( https://sap.github.io/ui5-webcomponents/playground/components/DatePicker/). I think that method will do the job for your case, as it is part of the DatePicker and it will always be up to date with the current format used. It's a method which receives a JS Date Object and returns a string with the date in the required by the DatePicker format.

Can you please check if this solution will work for you and get back to us?

Best Regards, Tsanislav

tsanislavgatev avatar Jul 29 '22 13:07 tsanislavgatev

Hello @tsanislavgatev, yes, this is possible to use, but not very common. I would expect, that I can set the min and max date formatting and localization independent. In React we've to use the reference of this component, only to format the date in a correct format, which is very strange. Thank you

ChewbaccaCookie avatar Aug 02 '22 12:08 ChewbaccaCookie

Hello @ChewbaccaCookie, Having it with a single date format, will cause difference between different APIs, for example, having it DD/MM/YYYY for all locales, or formatPatterns. This will cause having value and min/max dates with different string formats, which is a non consistent behaviour. That's why we have suggested using the format. Setting a formatPattern should also help having all properties expecting the same format. Can you please take a look if one of the two suggested solutions can help you solving the case?

Best Regards, Tsanislav

tsanislavgatev avatar Aug 30 '22 11:08 tsanislavgatev

We've now used the formatValue method. It works. Thank you

ChewbaccaCookie avatar Sep 08 '22 11:09 ChewbaccaCookie