feat(ui5-time-picker): display-value and value-format properties are introduced#13071
feat(ui5-time-picker): display-value and value-format properties are introduced#13071
Conversation
|
🚀 Deployed on https://pr-13071--ui5-webcomponents-preview.netlify.app |
packages/website/docs/_samples/main/TimePicker/CustomFormatting/sample.html
Outdated
Show resolved
Hide resolved
packages/main/src/TimePicker.ts
Outdated
There was a problem hiding this comment.
Fix documentation here as well, I did it in ui5-date-picker
packages/main/src/TimePicker.ts
Outdated
| _isoFormatInstance?: DateFormat; | ||
| _displayFormatInstance?: DateFormat; | ||
| _valueFormatInstance?: DateFormat; | ||
| _lastDisplayFormatPattern?: string; |
There was a problem hiding this comment.
why do we need this?
packages/main/src/TimePicker.ts
Outdated
| _displayFormatInstance?: DateFormat; | ||
| _valueFormatInstance?: DateFormat; | ||
| _lastDisplayFormatPattern?: string; | ||
| _lastValueFormatPattern?: string; |
There was a problem hiding this comment.
why do we need this?
packages/main/src/TimePicker.ts
Outdated
| let parsedValue = this.getValueFormat().parse(this.value, true); | ||
| if (!parsedValue) { | ||
| // If it doesn't parse as valueFormat, try displayFormat | ||
| parsedValue = this.getDisplayFormat().parse(this.value, true); |
There was a problem hiding this comment.
the flow should be valueFormat->formatPattern->iso, the display format should not be a fallback format
packages/main/src/TimePicker.ts
Outdated
|
|
||
| // @ts-ignore oFormatOptions is a private API of DateFormat | ||
| return this.getFormat().oFormatOptions.pattern as string; | ||
| return this.getISOFormat().oFormatOptions.pattern as string; |
There was a problem hiding this comment.
display default should be "medium", not ISO
packages/main/src/TimePicker.ts
Outdated
| } | ||
|
|
||
| // Try to parse as valueFormat and display in displayFormat | ||
| const parsedValue = this.getValueFormat().parse(this.value, true); |
There was a problem hiding this comment.
we should always have a display format, either set by the application or with formatpattern or with ISO
| return this.getISOFormat(); | ||
| } | ||
|
|
||
| const pattern = this._valueFormat; | ||
|
|
||
| // Return cached instance if pattern hasn't changed | ||
| if (this._valueFormatInstance && this._lastValueFormatPattern === pattern) { | ||
| return this._valueFormatInstance; | ||
| } | ||
|
|
||
| this._lastValueFormatPattern = pattern; | ||
|
|
||
| if (this._isValueFormatPattern) { | ||
| this._valueFormatInstance = DateFormat.getTimeInstance({ | ||
| strictParsing: true, | ||
| pattern: this._valueFormat, | ||
| }); | ||
| } else { | ||
| this._valueFormatInstance = DateFormat.getTimeInstance({ | ||
| strictParsing: true, | ||
| style: this._valueFormat, | ||
| }); | ||
| } | ||
|
|
||
| return this._valueFormatInstance; | ||
| } | ||
|
|
There was a problem hiding this comment.
we should simplify this
packages/main/src/TimePicker.ts
Outdated
| const pattern = this._displayFormat; | ||
|
|
||
| // Return cached instance if pattern hasn't changed | ||
| if (this._displayFormatInstance && this._lastDisplayFormatPattern === pattern) { | ||
| return this._displayFormatInstance; | ||
| } | ||
|
|
||
| this._lastDisplayFormatPattern = pattern; | ||
|
|
||
| if (this._isDisplayFormatPattern) { | ||
| this._displayFormatInstance = DateFormat.getTimeInstance({ | ||
| strictParsing: true, | ||
| pattern: this._displayFormat, | ||
| }); | ||
| } else { | ||
| this._displayFormatInstance = DateFormat.getTimeInstance({ | ||
| strictParsing: true, | ||
| style: this._displayFormat, | ||
| }); | ||
| } | ||
|
|
||
| return this._displayFormatInstance; |
There was a problem hiding this comment.
We should simplify this
This PR introduces display-value and value-format properties to the ui5-time-picker component
Changes: