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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user