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.5k stars 260 forks source link

[ui5-special-date]: value does not respect format-pattern of ui5-calendar #9067

Closed floa93 closed 2 months ago

floa93 commented 3 months ago

Bug Description

If a ui5-special-date is given with a value(e.g. value="20240528" ) in the format-pattern of the parent ui5-calendar(e.g. format-pattern="yyyyMMdd" ) an javascript error occurs and the calendar doesn't render.

This calendar typescript code uses the Javascript date function https://github.com/SAP/ui5-webcomponents/blob/648717aabe3e9e1570ea54100edd5e922cd1b651/packages/main/src/Calendar.ts#L345 , which does not respect the format-pattern like done in https://github.com/SAP/ui5-webcomponents/blob/648717aabe3e9e1570ea54100edd5e922cd1b651/packages/main/src/Calendar.ts#L325 to check if this is a valid special date.

Affected Component

ui5-special-date

Expected Behaviour

The calendar special date should be usable with the custom format-pattern given

Isolated Example

No response

Steps to Reproduce

<ui5-calendar format-pattern="yyyyMMdd" hide-week-numbers min-date="20240501" max-date="20241224">
    <ui5-special-date slot="specialDates" ui5-special-date value="20240528" type="Type01"></ui5-special-date>
</ui5-calendar>

Workaround: use a valid new date() format like yyyy-MM-dd

<ui5-calendar format-pattern="yyyy-MM-dd" hide-week-numbers min-date="2024-05-01" max-date="2024-12-24">
    <ui5-special-date slot="specialDates" ui5-special-date value="2024-05-28" type="Type01"></ui5-special-date>
</ui5-calendar>

### Log Output, Stack Trace or Screenshots

CalendarDate.js:143 Uncaught (in promise) Error: Date parameter must be a JavaScript Date object: [Invalid Date]. at CalendarDate.fromLocalJSDate (CalendarDate.js:143:1) at Calendar.js:186:46 at Array.forEach () at get _specialCalendarDates (Calendar.js:181:1) at Calendar.block0 (CalendarTemplate.lit.js:3:3983) at executeTemplate (executeTemplate.js:12:1) at Calendar.render (UI5Element.js:104:31) at updateShadowRoot (updateShadowRoot.js:20:1) at Calendar._render (UI5Element.js:580:29) at renderImmediately (Render.js:31:1)


### Priority

None

### UI5 Web Components Version

1.24.3

### Browser

Chrome, Edge, Firefox

### Operating System

Windows

### Additional Context

Its not a big issue since an easy workaround is to just use a valid new date() format like yyyy-MM-dd


### Organization

SAP

### Declaration

- [X] I’m not disclosing any internal or sensitive information.
plamenivanov91 commented 3 months ago

Hello @SAP/ui5-webcomponents-topic-b,

It seems value="20240528" is not recognized as valid date in our code.

Is this expected behavior ?

Also, the issue is reproducible in the main branch.

Regards, Plamen Ivanov