Release 1.19.7 (#3286)

* fix isWeekend() test for sunday fdow
* re-use the pattern for optgroup title
* prevent method on null
* composer update
* pre-select an option if it is the only available one
* added command to stop all active timesheets
This commit is contained in:
Kevin Papst
2022-05-07 23:47:32 +02:00
committed by GitHub
parent 100f8a5165
commit c8098b2e00
31 changed files with 818 additions and 484 deletions

View File

@@ -28,6 +28,10 @@ final class LocaleFormatExtensions extends AbstractExtension
private $formats;
private $security;
/**
* @var bool|null
*/
private $fdowSunday = null;
/**
* @var LocaleFormats|null
*/
@@ -77,14 +81,7 @@ final class LocaleFormatExtensions extends AbstractExtension
public function getTests()
{
return [
new TwigTest('weekend', function ($dateTime) {
if (!$dateTime instanceof \DateTime) {
return false;
}
$day = (int) $dateTime->format('w');
return ($day === 0 || $day === 6);
}),
new TwigTest('weekend', [$this, 'isWeekend']),
new TwigTest('today', function ($dateTime) {
if (!$dateTime instanceof \DateTime) {
return false;
@@ -149,6 +146,35 @@ final class LocaleFormatExtensions extends AbstractExtension
return $this->locale;
}
/**
* @param DateTime $dateTime
* @return bool
*/
public function isWeekend($dateTime): bool
{
if (!$dateTime instanceof \DateTime) {
return false;
}
$day = (int) $dateTime->format('w');
if ($this->fdowSunday === null) {
/** @var User|null $user */
$user = $this->security->getUser();
if ($user !== null) {
$this->fdowSunday = $user->isFirstDayOfWeekSunday();
} else {
$this->fdowSunday = false;
}
}
if ($this->fdowSunday) {
return ($day === 5 || $day === 6);
}
return ($day === 0 || $day === 6);
}
/**
* @param DateTime|string $date
* @return string