From 9b7dd6af733f84c5d03f10cbb67914d58c7e45ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zigmas=20Satkevi=C4=8Dius?= Date: Wed, 17 Apr 2024 11:09:13 +0300 Subject: [PATCH 1/3] fix: wrong protobuf duration --- src/Internal/Support/DateInterval.php | 2 +- .../Internal/Support/DateIntervalTestCase.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 tests/Unit/Internal/Support/DateIntervalTestCase.php diff --git a/src/Internal/Support/DateInterval.php b/src/Internal/Support/DateInterval.php index 4571c711..290c2623 100644 --- a/src/Internal/Support/DateInterval.php +++ b/src/Internal/Support/DateInterval.php @@ -162,7 +162,7 @@ public static function toDuration(\DateInterval $i = null): ?Duration $d = new Duration(); $parsed = self::parse($i); $d->setSeconds((int)$parsed->totalSeconds); - $d->setNanos($parsed->microseconds * 1000); + $d->setNanos(($parsed->totalMicroseconds % 1_000_000) * 1000); return $d; } diff --git a/tests/Unit/Internal/Support/DateIntervalTestCase.php b/tests/Unit/Internal/Support/DateIntervalTestCase.php new file mode 100644 index 00000000..b5e994d4 --- /dev/null +++ b/tests/Unit/Internal/Support/DateIntervalTestCase.php @@ -0,0 +1,17 @@ +assertEquals(356_000, $interval->getNanos()); + $this->assertEquals(5, $interval->getSeconds()); + } +} From 7efb77c16579307a5cf4968f64c2b2c8f30685a1 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 17 Apr 2024 19:27:43 +0400 Subject: [PATCH 2/3] Add constrain to `roadrunner-php/roadrunner-api-dto` version --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 380d05c2..e16dd9d8 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ "psr/log": "^2.0 || ^3.0", "ramsey/uuid": "^4.7", "react/promise": "^2.9", - "roadrunner-php/roadrunner-api-dto": "^1.5.0", + "roadrunner-php/roadrunner-api-dto": "^1.5.0 <1.7.0", "roadrunner-php/version-checker": "^1.0", "spiral/attributes": "^3.1.4", "spiral/roadrunner": "^2023.3.12 || ^2024.1", From 6584c02f43c2510ba135a30d1330c8e37618abf1 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Wed, 17 Apr 2024 19:33:48 +0400 Subject: [PATCH 3/3] Use `microseconds` property to better value extraction instead of `totalMicroseconds` --- src/Internal/Support/DateInterval.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Internal/Support/DateInterval.php b/src/Internal/Support/DateInterval.php index 290c2623..fd3dbac7 100644 --- a/src/Internal/Support/DateInterval.php +++ b/src/Internal/Support/DateInterval.php @@ -162,7 +162,7 @@ public static function toDuration(\DateInterval $i = null): ?Duration $d = new Duration(); $parsed = self::parse($i); $d->setSeconds((int)$parsed->totalSeconds); - $d->setNanos(($parsed->totalMicroseconds % 1_000_000) * 1000); + $d->setNanos(($parsed->microseconds % 1_000_000) * 1000); return $d; }