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
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions app/code/core/Mage/Customer/Block/Widget/Dob.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/

/**
* @method string getTime()
* @method DateTime getTime()
* @method $this setTime(string $value)
*/
class Mage_Customer_Block_Widget_Dob extends Mage_Customer_Block_Widget_Abstract
Expand Down Expand Up @@ -67,33 +67,49 @@ public function isRequired()
*/
public function setDate($date)
{
$this->setTime($date ? strtotime($date) : false);
if ($date) {
try {
$dateTime = new DateTime($date);
$this->setTime($dateTime);
} catch (Exception $e) {
}
}

$this->setData('date', $date);

return $this;
}

/**
* @return false|string
* @return bool
*/
public function hasTime()
{
return ($this->getTime() instanceof DateTime);
}

/**
* @return string
*/
public function getDay()
{
return $this->getTime() ? date('d', $this->getTime()) : '';
return ($this->hasTime()) ? $this->getTime()->format('d') : '';
}

/**
* @return false|string
* @return string
*/
public function getMonth()
{
return $this->getTime() ? date('m', $this->getTime()) : '';
return ($this->hasTime()) ? $this->getTime()->format('m') : '';
}

/**
* @return false|string
* @return string
*/
public function getYear()
{
return $this->getTime() ? date('Y', $this->getTime()) : '';
return ($this->hasTime()) ? $this->getTime()->format('o') : '';
}

/**
Expand Down