added decimal format variable for invoice duration (#1037)

This commit is contained in:
Kevin Papst
2019-08-15 21:31:13 +02:00
committed by GitHub
parent b5972bb680
commit 9611646bc6
10 changed files with 119 additions and 21 deletions

View File

@@ -80,6 +80,15 @@ class DebugRenderer implements RendererInterface
return $seconds;
}
/**
* @param mixed $seconds
* @return mixed
*/
protected function getFormattedDecimalDuration($seconds)
{
return $seconds;
}
/**
* Render the given InvoiceDocument with the data from the InvoiceModel into a stupid array for testing only.
*

View File

@@ -61,6 +61,7 @@ class DebugRendererTest extends TestCase
'invoice.vat',
'invoice.tax',
'invoice.total_time',
'invoice.duration_decimal',
'invoice.total',
'invoice.subtotal',
'template.name',
@@ -126,6 +127,7 @@ class DebugRendererTest extends TestCase
'entry.total',
'entry.currency',
'entry.duration',
'entry.duration_decimal',
'entry.duration_minutes',
'entry.begin',
'entry.begin_time',

View File

@@ -50,7 +50,7 @@ class ExtensionsTest extends TestCase
public function testGetFilters()
{
$filters = ['duration', 'money', 'currency', 'country', 'docu_link'];
$filters = ['duration', 'duration_decimal', 'money', 'currency', 'country', 'docu_link'];
$sut = $this->getSut($this->localeDe);
$twigFilters = $sut->getFilters();
$this->assertCount(count($filters), $twigFilters);
@@ -200,6 +200,33 @@ class ExtensionsTest extends TestCase
$this->assertEquals('00:00 h', $sut->duration(null));
}
public function testDurationDecimal()
{
$record = $this->getTimesheet(9437);
$sut = $this->getSut($this->localeEn);
$this->assertEquals('2.62', $sut->durationDecimal($record->getDuration()));
// test Timesheet object
$this->assertEquals('2.62', $sut->durationDecimal($record));
// test extended format
$sut = $this->getSut($this->localeDe, 'de');
$this->assertEquals('2,62', $sut->durationDecimal($record->getDuration()));
// test negative duration
$sut = $this->getSut($this->localeEn, 'en');
$this->assertEquals('0', $sut->durationDecimal('-1'));
// test zero duration
$sut = $this->getSut($this->localeEn, 'en');
$this->assertEquals('0', $sut->durationDecimal('0'));
$sut = $this->getSut($this->localeEn, 'en');
$this->assertEquals('0', $sut->durationDecimal(null));
}
protected function getTimesheet($seconds)
{
$begin = new \DateTime();