From 1aae4f4d0f66409822c9c2f1702b5c3d4935de2f Mon Sep 17 00:00:00 2001 From: Kevin Papst Date: Fri, 8 Jan 2021 15:12:42 +0100 Subject: [PATCH] fix first week in year shows wrong year (#2239) --- src/Timesheet/DateTimeFactory.php | 4 ++-- src/Widget/Type/PaginatedWorkingTimeChart.php | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Timesheet/DateTimeFactory.php b/src/Timesheet/DateTimeFactory.php index 3c037f73..bc5f6ac6 100644 --- a/src/Timesheet/DateTimeFactory.php +++ b/src/Timesheet/DateTimeFactory.php @@ -51,7 +51,7 @@ class DateTimeFactory $date = $this->createDateTime('now'); } - return $this->createWeekDateTime($date->format('Y'), $date->format('W'), 1, 0, 0, 0); + return $this->createWeekDateTime($date->format('o'), $date->format('W'), 1, 0, 0, 0); } public function getEndOfWeek(?DateTime $date = null): DateTime @@ -60,7 +60,7 @@ class DateTimeFactory $date = $this->createDateTime('now'); } - return $this->createWeekDateTime($date->format('Y'), $date->format('W'), 7, 23, 59, 59); + return $this->createWeekDateTime($date->format('o'), $date->format('W'), 7, 23, 59, 59); } public function getEndOfMonth(): DateTime diff --git a/src/Widget/Type/PaginatedWorkingTimeChart.php b/src/Widget/Type/PaginatedWorkingTimeChart.php index 94fa019e..4040dd74 100644 --- a/src/Widget/Type/PaginatedWorkingTimeChart.php +++ b/src/Widget/Type/PaginatedWorkingTimeChart.php @@ -27,7 +27,7 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget $this->setTitle('stats.yourWorkingHours'); $this->setOptions([ - 'year' => (new DateTime('now'))->format('Y'), + 'year' => (new DateTime('now'))->format('o'), 'week' => (new DateTime('now'))->format('W'), 'type' => 'bar', ]); @@ -38,7 +38,7 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget $this->setOption('user', $user); $now = new DateTime('now', new \DateTimeZone($user->getTimezone())); $this->setOptions([ - 'year' => $now->format('Y'), + 'year' => $now->format('o'), 'week' => $now->format('W'), ]); } @@ -90,7 +90,7 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget $thisMonth = clone $weekBegin; if ((int) $options['week'] === 1) { - $thisMonth = (new DateTime())->setISODate($options['year'], $options['week'], 7)->setTime(0, 0, 0); + $thisMonth = (new DateTime('now', $timezone))->setISODate($options['year'], $options['week'], 7)->setTime(0, 0, 0); } return [