Skip to content

Commit

Permalink
fix(datefield, datetimefield): comparison against empty string
Browse files Browse the repository at this point in the history
  • Loading branch information
btry committed Jun 16, 2023
1 parent ce07899 commit be4831c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions inc/field/datefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,15 @@ public function greaterThan($value): bool {
} else {
$answer = $this->value;
}
if (empty($value)) {
$value = '0000-00-00';
}
$answerDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $answer);
$answerDatetime->setTime(0, 0, 0, 0);
$compareDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $value);
if ($compareDatetime === false) {
return true;
}
$compareDatetime->setTime(0, 0, 0, 0);
return $answerDatetime > $compareDatetime;
}
Expand Down
6 changes: 6 additions & 0 deletions inc/field/datetimefield.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,14 @@ public function greaterThan($value): bool {
} else {
$answer = $this->value;
}
if (empty($value)) {
$value = '0000-00-00';
}
$answerDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $answer);
$compareDatetime = DateTime::createFromFormat(self::DATE_FORMAT, $value);
if ($compareDatetime === false) {
return true;
}
return $answerDatetime > $compareDatetime;
}

Expand Down

0 comments on commit be4831c

Please sign in to comment.