Skip to content

Commit dacba02

Browse files
authored
Fix Core Bug to make "01/01/1970" a valid birthday (#1851)
1 parent e286008 commit dacba02

File tree

1 file changed

+24
-8
lines changed
  • app/code/core/Mage/Customer/Block/Widget

1 file changed

+24
-8
lines changed

app/code/core/Mage/Customer/Block/Widget/Dob.php

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*/
2626

2727
/**
28-
* @method string getTime()
28+
* @method DateTime getTime()
2929
* @method $this setTime(string $value)
3030
*/
3131
class Mage_Customer_Block_Widget_Dob extends Mage_Customer_Block_Widget_Abstract
@@ -67,33 +67,49 @@ public function isRequired()
6767
*/
6868
public function setDate($date)
6969
{
70-
$this->setTime($date ? strtotime($date) : false);
70+
if ($date) {
71+
try {
72+
$dateTime = new DateTime($date);
73+
$this->setTime($dateTime);
74+
} catch (Exception $e) {
75+
}
76+
}
77+
7178
$this->setData('date', $date);
79+
7280
return $this;
7381
}
7482

7583
/**
76-
* @return false|string
84+
* @return bool
85+
*/
86+
public function hasTime()
87+
{
88+
return ($this->getTime() instanceof DateTime);
89+
}
90+
91+
/**
92+
* @return string
7793
*/
7894
public function getDay()
7995
{
80-
return $this->getTime() ? date('d', $this->getTime()) : '';
96+
return ($this->hasTime()) ? $this->getTime()->format('d') : '';
8197
}
8298

8399
/**
84-
* @return false|string
100+
* @return string
85101
*/
86102
public function getMonth()
87103
{
88-
return $this->getTime() ? date('m', $this->getTime()) : '';
104+
return ($this->hasTime()) ? $this->getTime()->format('m') : '';
89105
}
90106

91107
/**
92-
* @return false|string
108+
* @return string
93109
*/
94110
public function getYear()
95111
{
96-
return $this->getTime() ? date('Y', $this->getTime()) : '';
112+
return ($this->hasTime()) ? $this->getTime()->format('o') : '';
97113
}
98114

99115
/**

0 commit comments

Comments
 (0)