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),