[Form] Simplify DateTimeToStringTransformer
Avoid unneeded catch and re-throw of the same exception.
This commit is contained in:
parent
c94f18693e
commit
2c9b283e01
@ -90,7 +90,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
* Transforms a DateTime object into a date string with the configured format
|
* Transforms a DateTime object into a date string with the configured format
|
||||||
* and timezone.
|
* and timezone.
|
||||||
*
|
*
|
||||||
* @param \DateTime|\DateTimeInterface $dateTime A DateTime object
|
* @param \DateTime|\DateTimeInterface $value A DateTime object
|
||||||
*
|
*
|
||||||
* @return string A value as produced by PHP's date() function
|
* @return string A value as produced by PHP's date() function
|
||||||
*
|
*
|
||||||
@ -142,7 +142,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
throw new TransformationFailedException('Expected a string.');
|
throw new TransformationFailedException('Expected a string.');
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
|
||||||
$outputTz = new \DateTimeZone($this->outputTimezone);
|
$outputTz = new \DateTimeZone($this->outputTimezone);
|
||||||
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
|
$dateTime = \DateTime::createFromFormat($this->parseFormat, $value, $outputTz);
|
||||||
|
|
||||||
@ -157,6 +156,7 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
// On PHP versions < 5.3.7 we need to emulate the pipe operator
|
// On PHP versions < 5.3.7 we need to emulate the pipe operator
|
||||||
// and reset parts not given in the format to their equivalent
|
// and reset parts not given in the format to their equivalent
|
||||||
// of the UNIX base timestamp.
|
// of the UNIX base timestamp.
|
||||||
@ -224,8 +224,6 @@ class DateTimeToStringTransformer extends BaseDateTimeTransformer
|
|||||||
if ($this->inputTimezone !== $this->outputTimezone) {
|
if ($this->inputTimezone !== $this->outputTimezone) {
|
||||||
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
|
$dateTime->setTimezone(new \DateTimeZone($this->inputTimezone));
|
||||||
}
|
}
|
||||||
} catch (TransformationFailedException $e) {
|
|
||||||
throw $e;
|
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
throw new TransformationFailedException($e->getMessage(), $e->getCode(), $e);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user