Skip to content

Commit

Permalink
生年月日の一桁の月日の0を除去 EC-ECBE#1008
Browse files Browse the repository at this point in the history
  • Loading branch information
clicktx committed Sep 28, 2024
1 parent 74eaa0a commit 0324927
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions data/class/SC_FormParam.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,12 @@ public function setDBDate($db_date, $year_key = 'year', $month_key = 'month', $d
if (empty($db_date)) {
return;
}
list($y, $m, $d) = preg_split('/[- ]/', $db_date);
$this->setValue($year_key, $y);
$this->setValue($month_key, $m);
$this->setValue($day_key, $d);

// Smarty3以降は月日が1桁の場合、0埋めされていると補完されないため0を除去する
$objDate = new DateTime($db_date);
$this->setValue($year_key, $objDate->format('Y'));
$this->setValue($month_key, $objDate->format('n'));
$this->setValue($day_key, $objDate->format('j'));
}

// キーに対応した値をセットする。
Expand Down
8 changes: 4 additions & 4 deletions tests/class/SC_FormParamTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,11 @@ public function testSetDbDate()
$this->objFormParam->addParam('', 'month', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'NO_SPTAB', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));
$this->objFormParam->addParam('', 'day', STEXT_LEN, 'aKV', array('EXIST_CHECK', 'NO_SPTAB', 'SPTAB_CHECK', 'MAX_LENGTH_CHECK'));

$this->objFormParam->setDbDate('2019-04-01');
$this->objFormParam->setDbDate('2019-04-01 00:00:00');

$this->assertEquals('2019', $this->objFormParam->getValue('year'));
$this->assertEquals('04', $this->objFormParam->getValue('month'));
$this->assertEquals('01', $this->objFormParam->getValue('day'));
$this->assertSame('2019', $this->objFormParam->getValue('year'));
$this->assertSame('4', $this->objFormParam->getValue('month'));
$this->assertSame('1', $this->objFormParam->getValue('day'));
}

public function testSetDbDateWithEmpty()
Expand Down

0 comments on commit 0324927

Please sign in to comment.