wrong decimal duration for more than 1000 hours (#2214)

This commit is contained in:
Kevin Papst
2020-12-21 13:08:43 +01:00
committed by GitHub
parent 6ada0b649c
commit 74b3917e69
2 changed files with 12 additions and 1 deletions

View File

@@ -46,7 +46,12 @@ final class LocaleHelper
*/
public function durationDecimal(int $seconds)
{
return $this->getNumberFormatter()->format(number_format($seconds / 3600, 2));
$value = round($seconds / 3600, 2);
if ($value <= 0) {
$value = 0;
}
return $this->getNumberFormatter()->format($value);
}
/**

View File

@@ -198,6 +198,11 @@ class LocaleHelperTest extends TestCase
// test extended format
$sut = $this->getSut('de');
$this->assertEquals('2,62', $sut->durationDecimal($record->getDuration()));
$this->assertEquals('6.328,89', $sut->durationDecimal(22784012));
$this->assertEquals('1', $sut->durationDecimal(3600));
$this->assertEquals('1,01', $sut->durationDecimal(3630));
$this->assertEquals('1,02', $sut->durationDecimal(3661));
$this->assertEquals('1,1', $sut->durationDecimal(3960));
// test negative duration
$sut = $this->getSut('en');
@@ -206,6 +211,7 @@ class LocaleHelperTest extends TestCase
// test zero duration
$sut = $this->getSut('en');
$this->assertEquals('0', $sut->durationDecimal(0));
$this->assertEquals('6,328.89', $sut->durationDecimal(22784012));
}
protected function getTimesheet($seconds)