-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Error date time to save #11306
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
Error date time to save #11306
Conversation
\IntlDateFormatter::SHORT, | ||
]; | ||
protected $_allowedFormats | ||
= [ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please change this formatting back to normal & consistent with other code.
if (\Zend_Locale::isLocale($locale)) { | ||
$localeDate = $locale; | ||
} | ||
$date = $formatter->parse($date) ?: (new \Zend_Date( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Zend_Locale
and Zend_Date
must not be used, there was a separate refactoring effort to get rid of them and some static tests are checking they are not used.
There should be some intl
or PHP library equivalents.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur I have used this because the format date is in Zend
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@orlangur What can you recommend me to continue with this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only native intl
classes, like \DateTime
, \Locale
etc.
@@ -3,38 +3,47 @@ | |||
* Copyright © Magento, Inc. All rights reserved. | |||
* See COPYING.txt for license details. | |||
*/ | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some new lines are automatically added by your IDE, please avoid this.
@@ -218,6 +238,7 @@ public function scopeTimeStamp($scope = null) | |||
@date_default_timezone_set($timezone); | |||
$date = date('Y-m-d H:i:s'); | |||
@date_default_timezone_set($currentTimezone); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like some new lines are automatically added by your IDE, please avoid this.
Hi @raumatbel |
Hi @okorshenko, I have been very busy but in this week I'm going to try solve the problem with the tests |
Hi, Once approved, can these changes be merged into 2.1 and 2.2 aswell? |
That is the idea. Firstly I want solve this problem in the main branch and after I do the backports. |
Hi there @raumatbel I'm new to github so don't know the process. Thanks for letting me know. I've just seen so many issues reported under 2.1/2.2, fixed in 2.3-develop and then get forgotten. I didnt know if stuff gets automatically backported, or whether a new PR has to be created etc... Anyway, I see you have it in hand. Thanks |
Welcome @gwharton. |
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp(); | ||
|
||
$localeDate = !empty($locale) ? $locale : null; | ||
$date = $formatter->parse($date) ?: (new \Zend_Date( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still not solved: #11306 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to solve this problem, but it's not easy and it will take me a while fix it.
@@ -150,6 +158,7 @@ public function getDateTimeFormat($type) | |||
} | |||
|
|||
/** | |||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor bad smelling code instead of suppressing warning whenever possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This annotation needs to be removed and corresponding code refactored (unlike the PHPMD.CouplingBetweenObjects
it should be pretty easy).
I don't know if it is related, but there is another timezone/time/formatting bug in #10663 |
924cbe5
to
0d3b92e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for improving implementation using only native PHP classes!
After changes are applied, please force push as a single commit.
@@ -150,6 +158,7 @@ public function getDateTimeFormat($type) | |||
} | |||
|
|||
/** | |||
* @SuppressWarnings(PHPMD.CyclomaticComplexity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This annotation needs to be removed and corresponding code refactored (unlike the PHPMD.CouplingBetweenObjects
it should be pretty easy).
@@ -174,7 +183,13 @@ public function date($date = null, $locale = null, $useTimezone = true, $include | |||
$timeType, | |||
new \DateTimeZone($timezone) | |||
); | |||
|
|||
//Know if the date contains time or not | |||
if (!preg_match('/(.*).(\d{2}):(\d{2})/', $date)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at logic of this method I believe it should be rewritten into
if ($includeTime && !preg_match('\d{2}:\d{2}', $date))
(regexp note: no need in brackets, first part seems to be useless)
(comment could be removed with such condition)
@raumatbel would be nice to rebase against latest |
|
||
//Know if the date contains time or not | ||
if (!preg_match('/(.*).(\d{2}):(\d{2})/', $date)) { | ||
$date .= " 00:00:00"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With $timeType set to \IntlDateFormatter::SHORT
"00:00:00"
should be changed to "0:00am" to be parsed
0d3b92e
to
c77a9de
Compare
Hi @raumatbel, according to QA report #10485 is still reproduced after these changes. Could you please check if it works for you? |
Hi @orlangur I have checked the issue again. Without my changes the product I can not save it due to the problem of the dates, but with my changes it works fine. Do you can check again? If it doesn't work, can you indicate the steps to reproduce? |
Steps to reproduce: Expected result: Actual result |
Hi @raumatbel |
Hi @okorshenko , I apologize for the delay in answering but I'm very busy this weeks. This weekend I'm going to review again. I reopen PR |
@okorshenko @orlangur I have been reviewing and I have checked that with this PR this error is fixed. I attach the screenshots in the branch 2.3-develop and my branch with my solution. |
@raumatbel thank you for contributing. Please accept Community Contributors team invitation here to gain extended permissions for this repository. |
This fix works! Good job, @raumatbel |
@magento-engcom-team I had already permissions in this repository as "member". |
This problem is still present in 2.2.3 |
This problem appears in 2.1.9. Could somebody backport it? :) I would really appreciate! |
Description
Save date time correctly in different timezone and locale
Problem
The function
$formatter->parse($date)
always return false if the date doesn't contains time and the functionnew \DateTime($date)
return the error "Invalid input datetime format of value".Solution
Before of the function
$formatter->parse($date)
it checks if the string contains time or not. If it doesn't contains, it concat the value 00:00 to the string "date".Fixed Issues (if relevant)
Contribution checklist