Skip to content
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

'Publish at' date format after upgrade from 2.07 to 2.10 is correct but cannot be saved #30

Closed
PierAlex opened this issue Jul 19, 2016 · 19 comments

Comments

@PierAlex
Copy link

Hi,
My locale input format is dd/mm/yyyy
Calendar picker for the 'publish at' date insert the date correctly (dd/mm/yyyy).
Magento need the date in the mm/dd/yyyy date.
The problem is in Magento; however, is there a workaround to solve it?
Thanks.

@magefan
Copy link
Owner

magefan commented Jul 19, 2016

@PierAlex what version do you using? have you the latest one (2.2.3)?

@PierAlex
Copy link
Author

@magefan
installed the last version, same error.
image
If I write manually the date in the format 07/28/2016, it goes on.

@magefan
Copy link
Owner

magefan commented Jul 20, 2016

@PierAlex could you also tell what locale is setted on your magento and what locale is in your browser?

@PierAlex
Copy link
Author

PierAlex commented Jul 21, 2016

@magefan
Chrome
image

Magento
image

Maybe it can halps:
in Magento standard modules, the date is not always displayed in the same way. E.g. in the order grid, the purchase date is mmm, dd,yyyy.,.. but if I edit an order the same date is in dd/mmm/yyyy format.
For products, 'Set Product as New From' and 'to' dates are in the format mm/dd/yyyy and the calendar picker provide the date in this format.
image
For catalog price rules, in the grid, the date fields displays dd/mmm/yyyy but in edit, dates are in mm/dd/yyyy and the calendar picker provide this format
image

So it appears that there is not a standard, or that a standard is not respected in Maento standard modules, to display dates but there is a standard for dates input (mm/dd/yyyy) that not consider locales. Calendar pickers provides the same format mm/dd/yyyy.

In your case, the calendar provides tha date in the format dd/mm/yyyy that is correct for locale input but not for Magento standard.

For query filters such as orders reporting, the picker provide the date in the dd/mm/yyyy but those fields doesn't need to be saved.
image

Ale

@PierAlex
Copy link
Author

I just added an issue for magento. I think this is a Magento Issue. For a workaround it may be useful to have the picker in the Magento "standard" input format (mm/dd/yyyy) and an additional label that tells who inserts posts that the format for the date is mm/dd/yyyy to avoid wrong insertions (for dd<=12).

YATB

@PieterCappelle
Copy link

Having the same problem on Magento 2.1.0. Any updates on this?

@magefan
Copy link
Owner

magefan commented Aug 2, 2016

@PieterCappelle, cannot replicate this issue on own test environments. Could you please contact us (http://magefan.com/contact/), so we can check on your side, and provide a solution for the community?

@JacobDrummond
Copy link

Preconditions

  1. PHP 5.6.16
  2. MySQL 5.6.21-log
  3. Nginx 1.4.6
  4. Magento 2.1.0
    5 Install Magefan_Blog 2.2.4

Steps to reproduce

  1. In System > All Users > User > [You], set the interface locale to English (United Kingdom):
    blog-3
  2. Set blog post date to value where day is >12. (This is important, as Magento will wrongly guess that days <12 are months, meaning no validation error):
    blog-1

Expected result

  1. Successfully save blog post with new date

Actual result

  1. Validation error on UK-formatted date:
    blog-2

Cause

  1. Magefan (correctly) changes date format by locale in form block
  2. Magento appears to ignore date locale when processing forms. For example, dates in admin product forms are all American-format regardless of locale.

Solution

  1. Ignore locale date format until the rest of Magento catches up with Magefan?

@JacobDrummond
Copy link

JacobDrummond commented Aug 5, 2016

Temporary solution

app\code[Developer][YourModule]\etc\adminhtml\events.xml:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="magefan_blog_post_edit_tab_main_prepare_form">
        <observer name="[Developer]_[YourModule]_Observer_BlogPrepareForm" instance="[Developer]\[YourModule]\Observer\BlogPrepareForm" />
    </event>
</config>

app\code[Developer][YourModule]\Observer\BlogPrepareForm.php:

<?php

namespace [Developer]\[YourModule]\Observer;

class BlogPrepareForm implements \Magento\Framework\Event\ObserverInterface
{
    public function execute(\Magento\Framework\Event\Observer $observer)
    {
        /* @var \Magento\Framework\Data\Form $form*/
        $form = $observer->getEvent()->getForm();

        // Loop through form elements and set publish_time format to US
        foreach($form->getElements() as $fieldset)
        {
            foreach($fieldset->getElements() as $input)
            {
                if($input instanceof \Magento\Framework\Data\Form\Element\Date)
                {
                    $input->setDateFormat('MM/dd/y');
                }
            }
        }
    }
}

@woakley
Copy link

woakley commented Nov 28, 2016

I've tried the fix above but am now getting:

Something went wrong while saving this posts. DateTime::__construct(): Failed to parse time string (0,9/1,7/2,016) at position 0 (0): Unexpected character

@JacobDrummond
Copy link

@woakley, a few date/locale issues were resolved in Magento2 #6323. If you patch-in that fix, and undo the one above, do blog dates work again?

@magefan
Copy link
Owner

magefan commented Jan 3, 2017

We close this issue, as there was no new replies for a long time.

@magefan magefan closed this as completed Jan 3, 2017
@RForster92
Copy link

Experiencing this issue also in MG2.1.0. When trying to save/publish a blogpost, the datepicker adheres to the GB time, but then says "Please enter a valid date." as a message and won't save. If I type in the date in Americanized format, it then saves.

Is there any temporary solution until a proper fix at all?

firefox_screenshot_2017-01-06t09-47-21 557z

@magefan
Copy link
Owner

magefan commented Jan 9, 2017

@RForster92 , are you using blog extension greater 2.3.0? Can't replicate it on v2.4.2

@magefan magefan reopened this Jan 9, 2017
@RForster92
Copy link

We are using v2.2.0 of the blog extension on version 2.1.0 of Magento2

@magefan
Copy link
Owner

magefan commented Jan 23, 2017

@RForster92 , please update blog extension to the newest version (current newest version is 2.4.3).
Beginning from version 2.3.0 our blog extension use new ui for admin forms, so the issue must gone.

@kennedyabitbol
Copy link

Hi,

Update blog is not working Magento 2.1.12, Magefan Blog 2.8.0

@magefan
Copy link
Owner

magefan commented May 11, 2018

@kennedyabitbol , from what blog version you trying to update to v2.8.0 ?

@kennedyabitbol
Copy link

hi @magefan
I already got 2.8.0 installed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants