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

Fix Core Bug: To make "01/01/1970" a valid birthday #1851

Merged
merged 4 commits into from
May 29, 2022

Conversation

1Shiroyuuki1
Copy link
Contributor

When parsing "01/01/1970" as date to setDate() the output is '0'.
Because default value of strtoftime() is "01/01/1970".

    public function setDate($date)
    {
        $this->setTime($date ? strtotime($date) : false);
        $this->setData('date', $date);
        return $this;
    }

Description (*)

According to this bug means that Magento 1.X.X never allowed a birthday of "01/01/1970".
A simple null check in the getter will prevent it.

Manual testing scenarios (*)

  1. https://www.tehplayground.com/auf4jhP1T5thJDtK
  2. Text form:
<?php
// example code

//setDate() simulation
$customerBirthday = '01/01/1970';
$isDate             = $customerBirthday ? strtotime($customerBirthday) : false;

//getDate() simulation
$isDate ? print('Yeaj 01/01/1970 is valid') : print('but it´s not...');

//fix
($isDate !== null) ? print('Yeaj 01/01/1970 is valid') : print('but it´s not...');

?>

Contribution checklist (*)

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All automated tests passed successfully (all builds are green)
  • [Having Issues] Add yourself to contributors list

@github-actions github-actions bot added the Component: Customer Relates to Mage_Customer label Oct 5, 2021
kiatng
kiatng previously approved these changes Oct 5, 2021
Copy link
Contributor

@kiatng kiatng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested setting the dob to 01/01/1970 in both frontend and backend. Actually, the dob is set correctly in both cases. However, in frontend, the dob was empty even though its value is 01/01/1970. This PR fixes it.

image

@kiatng kiatng added the bug label Oct 5, 2021
@1Shiroyuuki1
Copy link
Contributor Author

Is it possible to merge this as asap ? , i´ve got another core bug which would result on this issue and a fix as well

elidrissidev
elidrissidev previously approved these changes Oct 6, 2021
addison74
addison74 previously approved these changes Oct 6, 2021
@1Shiroyuuki1 1Shiroyuuki1 dismissed stale reviews from addison74, elidrissidev, and kiatng via 3d97c32 October 6, 2021 15:05
@1Shiroyuuki1
Copy link
Contributor Author

I have fixed a following bug after this fix.
@kiatng strtotime returns via default a value of "01/01/1970". If you create a new customer and leave birthday input empty you will get this value as default birthday.

Steps to Reproduce:
(Frontend)

  1. Create a new Customer
  2. Leave Birthday input Empty
  3. Save
  4. Try to edit this customer again and you will see the default value of strtotime()

Fix: I have improved the settime() and getTime() method and replaced strtotime with a Datetime. There is absolutely no reason to parse a unix timestamp for a birthday date.
Since strtotime was very often used in php 4.x.x i think adobe never cares to improve their Date handling.
With us now supporting PHP 7++ we should consider to clean up this as well.

Awaiting new Review :)

@1Shiroyuuki1 1Shiroyuuki1 requested a review from kiatng October 6, 2021 15:14
@1Shiroyuuki1 1Shiroyuuki1 changed the title Fix Magento core Bug: Added null check to make "01/01/1970" a valid birthday Fix Core Bug: To make "01/01/1970" a valid birthday Oct 6, 2021
fballiano
fballiano previously approved these changes Dec 20, 2021
Added variable type to doctype

Co-authored-by: Ng Kiat Siong <[email protected]>
@kiatng
Copy link
Contributor

kiatng commented Mar 24, 2022

@1Shiroyuuki1 I tested your commit and it worked as expected. One last request from me:

The docblock needs to be updated:

  * @method DateTime getTime() 

Please do another commit.

@1Shiroyuuki1
Copy link
Contributor Author

1Shiroyuuki1 commented Mar 24, 2022

@kiatng done 👍

@fballiano fballiano merged commit dacba02 into OpenMage:1.9.4.x May 29, 2022
@github-actions
Copy link
Contributor

Unit Test Results

1 files  ±0  1 suites  ±0   0s ⏱️ ±0s
0 tests ±0  0 ✔️ ±0  0 💤 ±0  0 ❌ ±0 
7 runs  ±0  5 ✔️ ±0  2 💤 ±0  0 ❌ ±0 

Results for commit dacba02. ± Comparison against base commit 3ef5922.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Component: Customer Relates to Mage_Customer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants