Skip to content

Commit

Permalink
fix #3160 公開日時を開始日時を2/23、終了日時2/22で保存を試すと、保存が可能です。
Browse files Browse the repository at this point in the history
  • Loading branch information
dovanhung committed Feb 27, 2024
1 parent 73f8723 commit f9045aa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
8 changes: 5 additions & 3 deletions plugins/baser-core/src/Model/Validation/BcValidation.php
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ public static function checkDateRange($value, $fields, $context)
/**
* 指定した日付よりも新しい日付かどうかチェックする
*
* @param \Cake\I18n\DateTime $fieldValue 対象となる日付
* @param string $fieldValue 対象となる日付
* @param array $context
* @return bool
* @checked
Expand All @@ -445,8 +445,10 @@ public static function checkDateRange($value, $fields, $context)
*/
public static function checkDateAfterThan($fieldValue, $target, $context)
{
if ($fieldValue instanceof \Cake\I18n\DateTime && !empty($context['data'][$target])) {
return $fieldValue->greaterThan($context['data'][$target]);
if (!empty($fieldValue) && !empty($context['data'][$target])) {
$startDate = new FrozenTime($fieldValue);
$endDate = new FrozenTime($context['data'][$target]);
return $startDate->greaterThan($endDate);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,10 +486,10 @@ public function testCheckDateAfterThan($value, $target, $expect)
public static function checkDataAfterThanDataProvider()
{
return [
[new FrozenTime('2015-01-01 00:00:00'), new FrozenTime('2015-01-01 00:00:00'), false],
[new FrozenTime('2015-01-01 24:00:01'), new FrozenTime('2015-01-02 00:00:00'), true],
[new FrozenTime('2015-01-01 00:00:00'), new FrozenTime('2015-01-02 00:00:00'), false],
[new FrozenTime('2015-01-02 00:00:00'), new FrozenTime('2015-01-01 00:00:00'), true],
['2015-01-01 00:00:00', '2015-01-01 00:00:00', false],
['2015-01-01 24:00:01', '2015-01-02 00:00:00', true],
['2015-01-01 00:00:00', '2015-01-02 00:00:00', false],
['2015-01-02 00:00:00', '2015-01-01 00:00:00', true],
];
}

Expand Down

0 comments on commit f9045aa

Please sign in to comment.