- Fixed: DbDateValidator returns Unix epoch based date when invalid format is used

This commit is contained in:
buddh4 2020-01-13 11:27:22 +01:00
parent b9eefb2ddd
commit 0b4ecd3403
2 changed files with 6 additions and 4 deletions

View File

@ -74,7 +74,7 @@ class DateHelper
* *
* @param string $value * @param string $value
* @param string $timeValue optional time value * @param string $timeValue optional time value
* @return int timestamp in utc * @return int|false timestamp in utc
* @throws \Exception * @throws \Exception
*/ */
public static function parseDateTimeToTimestamp($value, $timeValue = null) public static function parseDateTimeToTimestamp($value, $timeValue = null)

View File

@ -99,7 +99,7 @@ class DbDateValidator extends DateValidator
* Parses a date and a time value if timeAttribute is specified. * Parses a date and a time value if timeAttribute is specified.
* *
* @param string $value * @param string $value
* @return int timestamp in utc * @return int|false timestamp in system timezone
* @throws \Exception * @throws \Exception
*/ */
protected function parseDateTimeValue($value, $timeValue = null) protected function parseDateTimeValue($value, $timeValue = null)
@ -111,7 +111,7 @@ class DbDateValidator extends DateValidator
$timestamp = $this->parseDateValue($value); $timestamp = $this->parseDateValue($value);
if ($this->hasTime() && !empty($timeValue)) { if ($timestamp !== false && $this->hasTime() && !empty($timeValue)) {
$timestamp += $this->parseTimeValue($timeValue); $timestamp += $this->parseTimeValue($timeValue);
$timestamp = $this->fixTimestampTimeZone($timestamp, $this->timeZone); $timestamp = $this->fixTimestampTimeZone($timestamp, $this->timeZone);
} }
@ -155,8 +155,10 @@ class DbDateValidator extends DateValidator
/** /**
* Parses a date and optionally a time if timeAttribute is specified. * Parses a date and optionally a time if timeAttribute is specified.
* *
* Returns false in case the value could not be parsed.
*
* @param string $value * @param string $value
* @return int timestamp in utc * @return int|false
* @throws \Exception * @throws \Exception
*/ */
public static function parseDateTime($value, $timeValue = null) public static function parseDateTime($value, $timeValue = null)