Skip to content

Commit f9d4756

Browse files
authored
Merge pull request #424: fix DateInterval to protobuf Duration converting
2 parents 03c654c + 6584c02 commit f9d4756

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"psr/log": "^2.0 || ^3.0",
3232
"ramsey/uuid": "^4.7",
3333
"react/promise": "^2.9",
34-
"roadrunner-php/roadrunner-api-dto": "^1.5.0",
34+
"roadrunner-php/roadrunner-api-dto": "^1.5.0 <1.7.0",
3535
"roadrunner-php/version-checker": "^1.0",
3636
"spiral/attributes": "^3.1.4",
3737
"spiral/roadrunner": "^2023.3.12 || ^2024.1",

src/Internal/Support/DateInterval.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public static function toDuration(\DateInterval $i = null): ?Duration
162162
$d = new Duration();
163163
$parsed = self::parse($i);
164164
$d->setSeconds((int)$parsed->totalSeconds);
165-
$d->setNanos($parsed->microseconds * 1000);
165+
$d->setNanos(($parsed->microseconds % 1_000_000) * 1000);
166166

167167
return $d;
168168
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Temporal\Tests\Unit\Internal\Support;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use Temporal\Internal\Support\DateInterval;
7+
8+
class DateIntervalTestCase extends TestCase
9+
{
10+
public function testFloatyDateIntervalToDuration(): void
11+
{
12+
$interval = DateInterval::toDuration(DateInterval::parse(5_000_356_000, DateInterval::FORMAT_NANOSECONDS));
13+
14+
$this->assertEquals(356_000, $interval->getNanos());
15+
$this->assertEquals(5, $interval->getSeconds());
16+
}
17+
}

0 commit comments

Comments
 (0)