Skip to content

Commit

Permalink
Fix setting date properties from an empty date object.
Browse files Browse the repository at this point in the history
If $date->month is set, before $date->mday is set it was incorrectly
being adjusted down. This would happen, e.g., when creating a new
date object, with no parameters then manually setting the month
property before setting the mday property.
  • Loading branch information
mrubinsk committed Dec 22, 2013
1 parent f2f9ee8 commit 4c5c424
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion framework/Date/lib/Horde/Date.php
Expand Up @@ -1114,7 +1114,9 @@ protected function _correct($mask = self::MASK_ALLPARTS, $down = false)
$this->_correctMonth();
/* When correcting the month, always correct the day too. Months
* have different numbers of days. */
$mask |= self::MASK_DAY;
if (!empty($this->_mday)) {
$mask |= self::MASK_DAY;
}
}

if ($mask & self::MASK_DAY) {
Expand Down
9 changes: 9 additions & 0 deletions framework/Date/test/Horde/Date/DateTest.php
Expand Up @@ -142,6 +142,15 @@ public function testDateCorrection()
$this->assertEquals(28, $d->day);
}

public function testSettingDatePropertiesFromEmptyDateObject()
{
$d = new Horde_Date();
$d->year = 2013;
$d->month = 12;
$d->mday = 20;
$this->assertEquals(12, $d->month);
}

public function testTimestamp()
{
$oldTimezone = date_default_timezone_get();
Expand Down

0 comments on commit 4c5c424

Please sign in to comment.