dashboard: fix years with 53 weeks (#2206)

This commit is contained in:
Kevin Papst
2020-12-18 13:09:28 +01:00
committed by GitHub
parent e21fc656e4
commit 6ada0b649c
2 changed files with 24 additions and 5 deletions

View File

@@ -63,6 +63,14 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
return $now;
}
private function getLastWeekInYear($year): int
{
$lastWeekInYear = new DateTime();
$lastWeekInYear->setISODate($year, 53);
return $lastWeekInYear->format('W') === '53' ? 53 : 52;
}
public function getData(array $options = [])
{
$options = $this->getOptions($options);
@@ -77,10 +85,21 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
$weekBegin = $this->getDate($timezone, $options['year'], $options['week'], 1, 0, 0, 0);
$weekEnd = $this->getDate($timezone, $options['year'], $options['week'], 7, 23, 59, 59);
$lastWeekInYear = $this->getLastWeekInYear($options['year']);
$lastWeekInLastYear = $this->getLastWeekInYear($options['year'] - 1);
$thisMonth = clone $weekBegin;
if ((int) $options['week'] === 1) {
$thisMonth = (new DateTime())->setISODate($options['year'], $options['week'], 7)->setTime(0, 0, 0);
}
return [
'begin' => clone $weekBegin,
'end' => clone $weekEnd,
'stats' => $this->repository->getDailyStats($user, $weekBegin, $weekEnd),
'thisMonth' => $thisMonth,
'lastWeekInYear' => $lastWeekInYear,
'lastWeekInLastYear' => $lastWeekInLastYear,
'day' => $this->repository->getStatistic(
'duration',
new DateTime('00:00:00', $timezone),

View File

@@ -13,13 +13,13 @@
{% set prevWeek = options.week %}
{% set nextYear = options.year %}
{% set nextWeek = options.week %}
{% if prevWeek == 1 %}
{% if options.week == 1 %}
{% set prevYear = prevYear - 1 %}
{% set prevWeek = 52 %}
{% set prevWeek = data.lastWeekInLastYear %}
{% else %}
{% set prevWeek = prevWeek - 1 %}
{% endif %}
{% if nextWeek == 52 %}
{% if options.week == data.lastWeekInYear %}
{% set nextYear = nextYear + 1 %}
{% set nextWeek = 1 %}
{% else %}
@@ -53,13 +53,13 @@
<div class="col-sm-3 col-xs-6">
<div class="description-block border-right">
<h5 class="description-header">{{ data.month|duration }}</h5>
<span class="description-text">{{ 'stats.workingTimeMonth'|trans({'%month%': data.begin|month_name, '%year%': data.begin|date_format('Y')}) }}</span>
<span class="description-text">{{ 'stats.workingTimeMonth'|trans({'%month%': data.thisMonth|month_name, '%year%': data.thisMonth|date_format('Y')}) }}</span>
</div>
</div>
<div class="col-sm-3 col-xs-6">
<div class="description-block border-right">
<h5 class="description-header">{{ data.year|duration }}</h5>
<span class="description-text">{{ 'stats.workingTimeYear'|trans({'%year%': data.begin|date_format('Y')}) }}</span>
<span class="description-text">{{ 'stats.workingTimeYear'|trans({'%year%': data.thisMonth|date_format('Y')}) }}</span>
</div>
</div>
</div>