bugfix for duration_only mode #137 (#142)

* replaced durationForEntry with duration filter
* fixed duration problem - fixes #137
This commit is contained in:
Kevin Papst
2018-06-02 19:39:03 +02:00
committed by GitHub
parent 1c0f8cdad1
commit 9d9860e495
10 changed files with 20 additions and 35 deletions

View File

@@ -1,6 +1,6 @@
avanzu_admin_theme: avanzu_admin_theme:
use_twig: true use_twig: true
use_assetic: true use_assetic: false
bower_bin: "/usr/local/bin/bower" bower_bin: "/usr/local/bin/bower"
options: options:
default_avatar: build/images/default_avatar.png default_avatar: build/images/default_avatar.png

View File

@@ -3,7 +3,7 @@ kimai:
timesheet: timesheet:
# Whether we display start and end time columns (false) or durations only (true). # Whether we display start and end time columns (false) or durations only (true).
# Setting this to true will also change the "edit timesheet" forms, more infos available in the confiugrations docu. # Setting this to true will also change the "edit timesheet" forms, more infos available in the configurations docu.
duration_only: false duration_only: false
# Rounding rules are used to round the begin & end dates and the duration for timesheet records. # Rounding rules are used to round the begin & end dates and the duration for timesheet records.

View File

@@ -116,7 +116,7 @@ class AppFixtures extends Fixture
// no alias to test twig username macro // no alias to test twig username macro
[ [
null, 'Super Administrator', self::USERNAME_SUPER_ADMIN, 'susan_super@example.com', 'ROLE_SUPER_ADMIN', null, 'Super Administrator', self::USERNAME_SUPER_ADMIN, 'susan_super@example.com', 'ROLE_SUPER_ADMIN',
'/bundles/avanzuadmintheme/img/avatar.png', true '/build/images/default_avatar.png', true
] ]
]; ];
} }

View File

@@ -11,7 +11,6 @@ namespace App\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
/** /**
@@ -60,7 +59,7 @@ class DoctrineCompilerPass implements CompilerPassInterface
if ($engine === null) { if ($engine === null) {
throw new \Exception( throw new \Exception(
'Could not detect database engine. Please set the environment config DATABASE_ENGINE ' . 'Could not detect database engine. Please set the environment config DATABASE_ENGINE ' .
'to one ' . implode(', ', $this->allowedEngines) . ', e.g. in your .env file: DATABASE_ENGINE=sqlite' 'to one of: "' . implode(', ', $this->allowedEngines) . '" in your .env file: DATABASE_ENGINE=sqlite'
); );
} }

View File

@@ -156,20 +156,12 @@ class Timesheet
/** /**
* Get duration * Get duration
* Do not rely on the results of this method for active records.
* *
* @return integer * @return integer
*/ */
public function getDuration() public function getDuration()
{ {
if ($this->begin === null) {
return 0;
}
if ($this->end === null) {
$current = new \DateTime();
return $current->getTimestamp() - $this->begin->getTimestamp();
}
return $this->duration; return $this->duration;
} }

View File

@@ -46,7 +46,6 @@ class Extensions extends \Twig_Extension
{ {
return [ return [
new TwigFilter('duration', [$this, 'duration']), new TwigFilter('duration', [$this, 'duration']),
new TwigFilter('durationForEntry', [$this, 'durationForEntry']),
new TwigFilter('money', [$this, 'money']), new TwigFilter('money', [$this, 'money']),
new TwigFilter('currency', [$this, 'currency']), new TwigFilter('currency', [$this, 'currency']),
new TwigFilter('country', [$this, 'country']), new TwigFilter('country', [$this, 'country']),
@@ -63,27 +62,22 @@ class Extensions extends \Twig_Extension
]; ];
} }
/**
* Returns the formatted duration for a Timesheet entry.
*
* @param Timesheet $entry
* @param bool $includeSeconds
* @return string
*/
public function durationForEntry(Timesheet $entry, $includeSeconds = false)
{
return $this->duration($entry->getDuration(), $includeSeconds);
}
/** /**
* Transforms seconds into a duration string. * Transforms seconds into a duration string.
* *
* @param $seconds * @param int|Timesheet $duration
* @param bool $includeSeconds * @param bool $includeSeconds
* @return string * @return string
*/ */
public function duration($seconds, $includeSeconds = false) public function duration($duration, $includeSeconds = false)
{ {
$seconds = $duration;
if ($duration instanceof Timesheet) {
$seconds = $duration->getDuration();
if ($duration->getEnd() === null) {
$seconds = time() - $duration->getBegin()->getTimestamp();
}
}
return $this->durationFormatter->format($seconds, $includeSeconds) . ' h'; return $this->durationFormatter->format($seconds, $includeSeconds) . ' h';
} }

View File

@@ -45,7 +45,7 @@
{% if not duration_only %} {% if not duration_only %}
<td class="hidden-xs">&dash;</td> <td class="hidden-xs">&dash;</td>
{% endif %} {% endif %}
<td><i>{{ entry.duration|duration }}</i></td> <td><i>{{ entry|duration }}</i></td>
<td>&dash;</td> <td>&dash;</td>
{% endif %} {% endif %}

View File

@@ -19,7 +19,7 @@
</div> </div>
<h4> <h4>
{{ entry.activity.name }} {{ entry.activity.name }}
<small><i class="fa fa-clock-o"></i> {{ entry|durationForEntry }}</small> <small><i class="fa fa-clock-o"></i> {{ entry|duration }}</small>
</h4> </h4>
<p>{{ entry.activity.project.name }} ({{ entry.activity.project.customer.name }})</p> <p>{{ entry.activity.project.name }} ({{ entry.activity.project.customer.name }})</p>
</a> </a>

View File

@@ -45,7 +45,7 @@
{% if not duration_only %} {% if not duration_only %}
<td>&dash;</td> <td>&dash;</td>
{% endif %} {% endif %}
<td class="hidden-xs"><i>{{ entry.duration|duration }}</i></td> <td class="hidden-xs"><i>{{ entry|duration }}</i></td>
<td class="hidden-xs">&dash;</td> <td class="hidden-xs">&dash;</td>
{% endif %} {% endif %}

View File

@@ -22,7 +22,7 @@ class ExtensionsTest extends TestCase
public function testGetFilters() public function testGetFilters()
{ {
$filters = ['duration', 'durationForEntry', 'money', 'currency', 'country']; $filters = ['duration', 'money', 'currency', 'country'];
$sut = new Extensions('de'); $sut = new Extensions('de');
$twigFilters = $sut->getFilters(); $twigFilters = $sut->getFilters();
$this->assertCount(count($filters), $twigFilters); $this->assertCount(count($filters), $twigFilters);
@@ -110,8 +110,8 @@ class ExtensionsTest extends TestCase
$this->assertEquals('02:37 h', $sut->duration($record->getDuration())); $this->assertEquals('02:37 h', $sut->duration($record->getDuration()));
$this->assertEquals('02:37:17 h', $sut->duration($record->getDuration(), true)); $this->assertEquals('02:37:17 h', $sut->duration($record->getDuration(), true));
$this->assertEquals('02:37 h', $sut->durationForEntry($record)); $this->assertEquals('02:37 h', $sut->duration($record));
$this->assertEquals('02:37:17 h', $sut->durationForEntry($record, true)); $this->assertEquals('02:37:17 h', $sut->duration($record, true));
} }
protected function getTimesheet($seconds) protected function getTimesheet($seconds)