forked from loafle/openapi-generator-original
[php][bug] Fix DateTime microseconds bug in ObjectSerializer (#11213)
* fixing precision for php * remove a bracket * handling whitespace * format comment * Use regexp to trim needless microseconds That way we can save timezone suffix. Co-authored-by: Carmen Quan <cquan@launchdarkly.com>
This commit is contained in:
@@ -64,4 +64,66 @@ class ObjectSerializerTest extends TestCase
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers ObjectSerializer::sanitizeTimestamp
|
||||
* @dataProvider provideTimestamps
|
||||
*/
|
||||
public function testSanitizeTimestamp(string $timestamp, string $expected): void
|
||||
{
|
||||
$this->assertEquals($expected, ObjectSerializer::sanitizeTimestamp($timestamp));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test datetime deserialization.
|
||||
*
|
||||
* @covers ObjectSerializer::deserialize
|
||||
* @dataProvider provideTimestamps
|
||||
*
|
||||
* @see https://github.com/OpenAPITools/openapi-generator/issues/7942
|
||||
* @see https://github.com/OpenAPITools/openapi-generator/issues/10548
|
||||
*/
|
||||
public function testDateTimeParseSecondAccuracy(string $timestamp, string $expected): void
|
||||
{
|
||||
$dateTime = ObjectSerializer::deserialize($timestamp, '\DateTime');
|
||||
$this->assertEquals(new \DateTime($expected), $dateTime);
|
||||
}
|
||||
|
||||
public function provideTimestamps(): array
|
||||
{
|
||||
return [
|
||||
'String from #7942' => [
|
||||
'2020-11-11T15:17:58.868722633Z',
|
||||
'2020-11-11T15:17:58.868722Z',
|
||||
],
|
||||
'String from #10548' => [
|
||||
'2021-10-06T20:17:16.076372256Z',
|
||||
'2021-10-06T20:17:16.076372Z',
|
||||
],
|
||||
'Without timezone' => [
|
||||
'2021-10-06T20:17:16.076372256',
|
||||
'2021-10-06T20:17:16.076372',
|
||||
],
|
||||
'Without microseconds' => [
|
||||
'2021-10-06T20:17:16',
|
||||
'2021-10-06T20:17:16',
|
||||
],
|
||||
'Without microseconds with timezone' => [
|
||||
'2021-10-06T20:17:16Z',
|
||||
'2021-10-06T20:17:16Z',
|
||||
],
|
||||
'With numeric timezone' => [
|
||||
'2021-10-06T20:17:16.076372256+03:00',
|
||||
'2021-10-06T20:17:16.076372+03:00',
|
||||
],
|
||||
'With numeric timezone without delimiter' => [
|
||||
'2021-10-06T20:17:16.076372256+0300',
|
||||
'2021-10-06T20:17:16.076372+0300',
|
||||
],
|
||||
'With numeric short timezone' => [
|
||||
'2021-10-06T20:17:16.076372256+03',
|
||||
'2021-10-06T20:17:16.076372+03',
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user