forked from loafle/openapi-generator-original
[php][bug] Fixes exceptions with API's with too high date-time nanosecond precision (#7943)
* [php] Fixes problems with API's with too high date-time nanosecond precision * update samples Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
parent
33f4827a06
commit
6f6822a1b7
@ -306,7 +306,15 @@ class ObjectSerializer
|
||||
// be interpreted as a missing field/value. Let's handle
|
||||
// this graceful.
|
||||
if (!empty($data)) {
|
||||
try {
|
||||
return new \DateTime($data);
|
||||
} catch (\Exception $exception) {
|
||||
// Some API's return a date-time with too high nanosecond
|
||||
// precision for php's DateTime to handle. This conversion
|
||||
// (string -> unix timestamp -> DateTime) is a workaround
|
||||
// for the problem.
|
||||
return (new \DateTime())->setTimestamp(strtotime($data));
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
@ -316,7 +316,15 @@ class ObjectSerializer
|
||||
// be interpreted as a missing field/value. Let's handle
|
||||
// this graceful.
|
||||
if (!empty($data)) {
|
||||
try {
|
||||
return new \DateTime($data);
|
||||
} catch (\Exception $exception) {
|
||||
// Some API's return a date-time with too high nanosecond
|
||||
// precision for php's DateTime to handle. This conversion
|
||||
// (string -> unix timestamp -> DateTime) is a workaround
|
||||
// for the problem.
|
||||
return (new \DateTime())->setTimestamp(strtotime($data));
|
||||
}
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user