Skip to content

Invalid date when timeOnly defined on datetime UIComponent #23157

Closed
@duckchip

Description

@duckchip

Preconditions (*)

  1. Magento 2.3.1

Steps to reproduce (*)

  1. Define a ui_component form.xml
  2. add a Datetime UI component with the option 'timeOnly' set to 'yes'
<field name="start_time"]
    [argument name="data" xsi:type="array"]
        [item name="config" xsi:type="array"]
            [item name="dataType" xsi:type="string"]string[/item]
            [item name="label" xsi:type="string" translate="true"]Start Time[/item]
            [item name="formElement" xsi:type="string"]date[/item]
            [item name="source" xsi:type="string"]import_profile[/item]
            [item name="dataScope" xsi:type="string"]start_time[/item]
            [item name="options" xsi:type="array"]
                [item name="timeOnlyTitle" xsi:type="string"]Select Start Time[/item]
                [item name="showsTime" xsi:type="boolean"]true[/item]
                [item name="timeOnly" xsi:type="boolean"]true[/item]
                [item name="timeFormat" xsi:type="string"]HH:mm:ss[/item]
                [item name="dateFormat" xsi:type="string"]yyyy-MM-dd[/item]
            [/item]
        [/item]
    [/argument]
[/field>
{code}
1. Save the form and check the result. 

### Expected result (*)
1. Correct time value

### Actual result (*)
1. The value states: 'Invalid Date'

### Additional information
This problem doesn't occur when the option 'timeOnly' is not defined. 

My best guess is that the problem happens inside the /module-ui/view/base/web/js/form/element/date.js at 'onShiftedValueChange' function..

{code}
 /**
        * Prepares and sets date/time value that will be sent
        * to the server.
        * * @param {String} shiftedValue
         */
        onShiftedValueChange: function (shiftedValue) {
            var value,
                formattedValue,
                momentValue;

            if (shiftedValue) {
                momentValue = moment(shiftedValue, this.pickerDateTimeFormat);

                if (this.options.showsTime) {
                    formattedValue = moment(momentValue).format(this.timezoneFormat);
                    //formattedValue returns an incorrect value. 
                    value = moment.tz(formattedValue, this.storeTimeZone).tz('UTC').toISOString();
                } else {
                    value = momentValue.format(this.outputDateFormat);
                }
            } else {
                value = '';
            }

            if (value !== this.value()) {
                this.value(value);
            }
        },

Metadata

Metadata

Assignees

Labels

Component: AdminComponent: UiIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: doneReproduced on 2.2.xThe issue has been reproduced on latest 2.2 releaseReproduced on 2.3.xThe issue has been reproduced on latest 2.3 releaseSeverity: S2Major restrictions or short-term circumventions are required until a fix is available.Triage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions