fix sunday being first day of week (#2483)
This commit is contained in:
@@ -13,6 +13,7 @@ use App\Entity\Activity;
|
||||
use App\Entity\Project;
|
||||
use App\Entity\User;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\DateTimeFactory;
|
||||
use DateTime;
|
||||
|
||||
class DailyWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
@@ -30,8 +31,8 @@ class DailyWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
$this->setId('DailyWorkingTimeChart');
|
||||
$this->setTitle('stats.yourWorkingHours');
|
||||
$this->setOptions([
|
||||
'begin' => 'monday this week 00:00:00',
|
||||
'end' => 'sunday this week 23:59:59',
|
||||
'begin' => null,
|
||||
'end' => null,
|
||||
'color' => '',
|
||||
'type' => self::DEFAULT_CHART,
|
||||
'id' => '',
|
||||
@@ -67,12 +68,22 @@ class DailyWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
throw new \InvalidArgumentException('Widget option "user" must be an instance of ' . User::class);
|
||||
}
|
||||
|
||||
$dateTimeFactory = DateTimeFactory::createByUser($user);
|
||||
|
||||
if ($options['begin'] === null) {
|
||||
$options['begin'] = $dateTimeFactory->getStartOfWeek();
|
||||
}
|
||||
|
||||
if ($options['begin'] instanceof DateTime) {
|
||||
$begin = $options['begin'];
|
||||
} else {
|
||||
$begin = new DateTime($options['begin'], new \DateTimeZone($user->getTimezone()));
|
||||
}
|
||||
|
||||
if ($options['end'] === null) {
|
||||
$options['end'] = $dateTimeFactory->getEndOfWeek($begin);
|
||||
}
|
||||
|
||||
if ($options['end'] instanceof DateTime) {
|
||||
$end = $options['end'];
|
||||
} else {
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace App\Widget\Type;
|
||||
|
||||
use App\Entity\User;
|
||||
use App\Repository\TimesheetRepository;
|
||||
use App\Timesheet\DateTimeFactory;
|
||||
use DateTime;
|
||||
|
||||
final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
@@ -54,15 +55,6 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
return $options;
|
||||
}
|
||||
|
||||
private function getDate(\DateTimeZone $timezone, $year, $week, $day, $hour, $minute, $second)
|
||||
{
|
||||
$now = new DateTime('now', $timezone);
|
||||
$now->setISODate($year, $week, $day);
|
||||
$now->setTime($hour, $minute, $second);
|
||||
|
||||
return $now;
|
||||
}
|
||||
|
||||
private function getLastWeekInYear($year): int
|
||||
{
|
||||
$lastWeekInYear = new DateTime();
|
||||
@@ -80,17 +72,23 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
throw new \InvalidArgumentException('Widget option "user" must be an instance of ' . User::class);
|
||||
}
|
||||
|
||||
$timezone = new \DateTimeZone($user->getTimezone());
|
||||
$dateTimeFactory = DateTimeFactory::createByUser($user);
|
||||
|
||||
$weekBegin = $this->getDate($timezone, $options['year'], $options['week'], 1, 0, 0, 0);
|
||||
$weekEnd = $this->getDate($timezone, $options['year'], $options['week'], 7, 23, 59, 59);
|
||||
$year = $options['year'];
|
||||
$week = $options['week'];
|
||||
|
||||
$lastWeekInYear = $this->getLastWeekInYear($options['year']);
|
||||
$lastWeekInLastYear = $this->getLastWeekInYear($options['year'] - 1);
|
||||
$weekBegin = ($dateTimeFactory->createDateTime())->setISODate($year, $week, 1)->setTime(0, 0, 0);
|
||||
$weekEnd = ($dateTimeFactory->createDateTime())->setISODate($year, $week, 7)->setTime(23, 59, 59);
|
||||
|
||||
$weekBegin = $dateTimeFactory->getStartOfWeek($weekBegin);
|
||||
$weekEnd = $dateTimeFactory->getEndOfWeek($weekEnd);
|
||||
|
||||
$lastWeekInYear = $this->getLastWeekInYear($year);
|
||||
$lastWeekInLastYear = $this->getLastWeekInYear($year - 1);
|
||||
|
||||
$thisMonth = clone $weekBegin;
|
||||
if ((int) $options['week'] === 1) {
|
||||
$thisMonth = (new DateTime('now', $timezone))->setISODate($options['year'], $options['week'], 7)->setTime(0, 0, 0);
|
||||
if ((int) $week === 1) {
|
||||
$thisMonth = ($dateTimeFactory->createDateTime())->setISODate($year, $week, 1)->setTime(0, 0, 0);
|
||||
}
|
||||
|
||||
return [
|
||||
@@ -102,8 +100,8 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
'lastWeekInLastYear' => $lastWeekInLastYear,
|
||||
'day' => $this->repository->getStatistic(
|
||||
'duration',
|
||||
new DateTime('00:00:00', $timezone),
|
||||
new DateTime('23:59:59', $timezone),
|
||||
$dateTimeFactory->createDateTime('00:00:00'),
|
||||
$dateTimeFactory->createDateTime('23:59:59'),
|
||||
$user
|
||||
),
|
||||
'week' => $this->repository->getStatistic(
|
||||
@@ -114,14 +112,14 @@ final class PaginatedWorkingTimeChart extends SimpleWidget implements UserWidget
|
||||
),
|
||||
'month' => $this->repository->getStatistic(
|
||||
'duration',
|
||||
(clone $weekBegin)->setDate($weekBegin->format('Y'), $weekBegin->format('n'), 1)->setTime(0, 0, 0),
|
||||
(clone $weekBegin)->setDate($weekBegin->format('Y'), $weekBegin->format('n'), $weekBegin->format('t'))->setTime(23, 59, 59),
|
||||
(clone $weekBegin)->setDate((int) $weekBegin->format('Y'), (int) $weekBegin->format('n'), 1)->setTime(0, 0, 0),
|
||||
(clone $weekBegin)->setDate((int) $weekBegin->format('Y'), (int) $weekBegin->format('n'), (int) $weekBegin->format('t'))->setTime(23, 59, 59),
|
||||
$user
|
||||
),
|
||||
'year' => $this->repository->getStatistic(
|
||||
'duration',
|
||||
new DateTime(sprintf('01 january %s 00:00:00', $options['year']), $timezone),
|
||||
new DateTime(sprintf('31 december %s 23:59:59', $options['year']), $timezone),
|
||||
$dateTimeFactory->createDateTime(sprintf('01 january %s 00:00:00', $year)),
|
||||
$dateTimeFactory->createDateTime(sprintf('31 december %s 23:59:59', $year)),
|
||||
$user
|
||||
),
|
||||
];
|
||||
|
||||
Reference in New Issue
Block a user