Skip to content

Commit

Permalink
Merge pull request #424: fix DateInterval to protobuf Duration conver…
Browse files Browse the repository at this point in the history
…ting
  • Loading branch information
roxblnfk authored Apr 17, 2024
2 parents 03c654c + 6584c02 commit f9d4756
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/Internal/Support/DateInterval.php
Original file line number Diff line number Diff line change
Expand Up @@ -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->microseconds % 1_000_000) * 1000);

return $d;
}
Expand Down
17 changes: 17 additions & 0 deletions tests/Unit/Internal/Support/DateIntervalTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace Temporal\Tests\Unit\Internal\Support;

use PHPUnit\Framework\TestCase;
use Temporal\Internal\Support\DateInterval;

class DateIntervalTestCase extends TestCase
{
public function testFloatyDateIntervalToDuration(): void
{
$interval = DateInterval::toDuration(DateInterval::parse(5_000_356_000, DateInterval::FORMAT_NANOSECONDS));

$this->assertEquals(356_000, $interval->getNanos());
$this->assertEquals(5, $interval->getSeconds());
}
}

0 comments on commit f9d4756

Please sign in to comment.