Skip to content

Magento 2.1.1 Invalid input date format 'Invalid date' #6831

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Nerogee opened this issue Oct 1, 2016 · 18 comments
Closed

Magento 2.1.1 Invalid input date format 'Invalid date' #6831

Nerogee opened this issue Oct 1, 2016 · 18 comments
Labels
Area: Frontend bug report Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@Nerogee
Copy link

Nerogee commented Oct 1, 2016

Preconditions

  1. Magento 2.1.1
  2. php 7.0.8

Steps to reproduce

  1. Create an admin listing by using Ui component
  2. There are date type column
  3. Enable the inlineEdit function for the date type column

Expected result

  1. When row is clicked and the inline editing mode enabled, the date column should be converted to the correct value in date picker UI
  2. Save the row should have no error

Actual result

  1. in editing mode, the date value showed in the Date Picker Ui will always shows the value of current date instead of the actual column value
  2. Randomly error Invalid input date format 'Invalid date' will show up, but if clicking the date picker something else seem to be triggered and then it would be fine to save from inlineEdit mode
@knowgod
Copy link

knowgod commented Jan 16, 2017

I experience this error on Magento ver. 2.1.3 (PHP 7.0.13).

@janeblonde
Copy link

This issue is killing me!
#7037

@tzyganu
Copy link
Contributor

tzyganu commented May 9, 2017

May I add that you don't even need to create your own listing using UI components.
It happens in the core modules also.
Steps to reproduce.

  • Go to Content->CMS->Pages list in the backend.
  • Edit a page (not inline edit - regular edit) and set a value for "Custom design from"
  • go back to the list
  • Make the "Custom Design from" column visible.
  • Inline edit the item that has a value for Custom design from"
  • Hit save without changing anything.

Expected result:

  • the page saves and I get a success message

Actual result:

  • I get an error message [Page ID: 1] Something went wrong while saving the page..

Additional details

  • here is how the post data looks like
items[1][title]=404+Not+Found&   
items[1][identifier]=no-route&  
items[1][page_layout]=2columns-right&  
items[1][is_active]=1&  
items[1][custom_theme_from]=Invalid+date&  
items[1][custom_theme_to]=&  
items[1][custom_theme]=&  
items[1][custom_root_template]=&  
items[1][meta_title]=&  
items[1][meta_keywords]=Page+keywords&  
items[1][meta_description]=Page+description&  
items[1][page_id]=1&  
form_key=(irelevant)

Notice the value for custom_theme_from.

Conclusion:
It works for empty date values and when you change the date in the inline edit, but it does not work when you inline edit something and you don't change a date field value.

@SatishDubariya
Copy link

I also have same problem while creating new product. While adding new product if 'Set Product as New FROM DATE to TO DATE', 'Schedule update FROM DATE to TO DATE', 'Special Price FROM DATE to TO DATE' any of the field have blank date then i get invalid date error and can not add product.
I am using en_GB locale interface and i tried again n again after changing it to en_US but still error generate.
Magento Version 2.1.5

@tobias-forkel
Copy link
Contributor

tobias-forkel commented Jul 31, 2017

In 2.1.1 we were able to fix the problem by updating the interface_locale back to en_US for all affected admin users.

UPDATE admin_user SET interface_locale = 'en_US' WHERE interface_locale = 'en_AU';

Clearly not a permanent solution, but better then the error.

@selusi
Copy link

selusi commented Sep 8, 2017

The bug is in the static content that Magento create for performace issue:

pub\static\adminhtml\Magento\backend{locale}\Magento_Ui\js\lib\validation\rules.js

In this file there are more rules about the validation of the date.
Example by considering locale = it_IT
There is a correct rule that check the date on basis of locale format:

"dateITA": [
            function(value) {
                var check = false;
                var re = /^\d{1,2}\/\d{1,2}\/\d{4}$/;
                if (re.test(value)) {
                    var adata = value.split('/');
                    var gg = parseInt(adata[0], 10);
                    var mm = parseInt(adata[1], 10);
                    var aaaa = parseInt(adata[2], 10);
                    var xdata = new Date(aaaa, mm - 1, gg);
                    if ((xdata.getFullYear() === aaaa) &&
                        (xdata.getMonth() === mm - 1) && (xdata.getDate() === gg )) {
                        check = true;
                    } else {
                        check = false;
                    }
                } else {
                    check = false;
                }
                return check;
            },
            $.mage.__('Please enter a correct date')
        ],

Below there is another rule that checks the date value without considering the locale format:

"validate-date": [
			function(value) {
                            var test = new Date(value);
                           return utils.isEmptyNoTrim(value) || !isNaN(test);
                         },
                       $.mage.__('Please enter a valid date.')
        ],

Replacing the function of the "validate-date" rule with the function of the "dateITA" (if the locale is it_IT) rule, the validation problem is resolved.
But persist the presentation problem, because you can save (in my case) the customer Date of Birthday correctly, but when you open the form again the date of DoB is wrong.
However this is the way to fix the bug definitively.
Tested on Magento 2.1.8 in the admin panel section.

@magento-engcom-team magento-engcom-team added 2.1.x bug report Area: Frontend Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed and removed G1 Passed labels Sep 8, 2017
@magento-team
Copy link
Contributor

Internal ticket to track issue progress: MAGETWO-80096

@magento-team magento-team added 2.2.x Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development labels Sep 27, 2017
@magento-engcom-team
Copy link
Contributor

Hi @Nerogee the issue has been fixed in #11067 by @joachimVT. The fix will be available in 2.2.1

@magento-engcom-team magento-engcom-team added Fixed in 2.1.x The issue has been fixed in 2.1 release line ready for backport labels Oct 6, 2017
@digvijay2017
Copy link

Not fixed 2.2.1.

magento2-1-1

@bahramdavoodi
Copy link

@digvijay2017 i hope this module help to you and any body.
Module Fix Date

@gianiaco
Copy link

I confirm issue.
@bahramdavodi , great module man, a little bug is in di.xml in type attribute, you have to replace with
<preference for="Magento\Framework\Stdlib\DateTime\Timezone" type="Magonex\DateTime\Framework\Timezone"/>

My version 2.2.1

@bahramdavoodi
Copy link

@gianiaco fixed. thanks

@digvijay2017
Copy link

digvijay2017 commented Dec 14, 2017

Hi @bahramdavodi

After installing your module, I am not getting the other date format in calendar. Calendar is always showing the US date format, because in your function, you have added 'en_US' hard coded. I think, it's not a proper solution.

  public function getDateFormat($type = \IntlDateFormatter::SHORT)
    {
        return (new \IntlDateFormatter(
        //$this->_localeResolver->getLocale(),
            'en_US',
            $type,
            \IntlDateFormatter::NONE
        ))->getPattern();
    }

@bahramdavoodi
Copy link

@digvijay2017 this problem is with libicu in centos. magento work well in the Ubuntu and Debian or Mac OS well.
i'm support magento for persian language and for now this is best solution.

i'm writting a new module for this problem. when this extension is finished, i published it.

thanks for you

@okorshenko
Copy link
Contributor

Hi @Nerogee. Thank you for your report.
The issue has been fixed in magento-engcom/magento2ce#1353 by @magento-engcom-team in 2.3-develop branch
Related commit(s):

The fix will be available with the upcoming 2.3.0 release.

@okorshenko okorshenko added the Fixed in 2.3.x The issue has been fixed in 2.3 release line label Feb 7, 2018
@magento-engcom-team magento-engcom-team added the Fixed in 2.2.x The issue has been fixed in 2.2 release line label Feb 22, 2018
@maxxeh1
Copy link

maxxeh1 commented Mar 20, 2018

Still experiencing in 2.2.3

@ghost
Copy link

ghost commented Apr 30, 2018

Also experiencing in 2.2.3, managed to fix it by switching my locale to en_US from en_GB but that's not a fix Magento.

@shikharomar01
Copy link

I am getting the same error in magento 2.3.5
Please Check
https://prnt.sc/sjlii0
I already applied Magonex extension for datetime, but it did not work for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Frontend bug report Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Fixed in 2.3.x The issue has been fixed in 2.3 release line Issue: Format is valid Gate 1 Passed. Automatic verification of issue format passed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests