diff -u b/core/lib/Drupal/Core/Datetime/DateHelper.php b/core/lib/Drupal/Core/Datetime/DateHelper.php --- b/core/lib/Drupal/Core/Datetime/DateHelper.php +++ b/core/lib/Drupal/Core/Datetime/DateHelper.php @@ -453,7 +453,7 @@ * The number of days in the month. */ public static function daysInMonth($date = NULL) { - if (isset($date)) { + if (isset($date) && !empty($date)) { if (!$date instanceof DrupalDateTime) { $date = new DrupalDateTime($date); } @@ -475,7 +475,7 @@ * The number of days in the year. */ public static function daysInYear($date = NULL) { - if (isset($date)) { + if (isset($date) && !empty($date)) { if (!$date instanceof DrupalDateTime) { $date = new DrupalDateTime($date); } @@ -502,7 +502,7 @@ * The number of the day in the week. */ public static function dayOfWeek($date = NULL) { - if (isset($date)) { + if (isset($date) && !empty($date)) { if (!$date instanceof DrupalDateTime) { $date = new DrupalDateTime($date); } @@ -527,7 +527,7 @@ * The name of the day in the week for that date. */ public static function dayOfWeekName($date = NULL, $abbr = TRUE) { - if (isset($date)) { + if (isset($date) && !empty($date)) { if (!$date instanceof DrupalDateTime) { $date = new DrupalDateTime($date); } diff -u b/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php --- b/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php +++ b/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php @@ -165,6 +165,10 @@ public function testDaysInMonth() { // Pass nothing and expect to get NULL. $this->assertNull(DateHelper::daysInMonth()); + $this->assertNull(DateHelper::daysInMonth(FALSE)); + $this->assertNull(DateHelper::daysInMonth(0)); + $this->assertNull(DateHelper::daysInMonth('0')); + $this->assertNull(DateHelper::daysInMonth('')); // December 31st 2022 is a Saturday. $value = '2022-12-31 00:00:00'; @@ -183,6 +187,10 @@ public function testDaysInYear() { // Pass nothing and expect to get NULL. $this->assertNull(DateHelper::daysInYear()); + $this->assertNull(DateHelper::daysInYear(FALSE)); + $this->assertNull(DateHelper::daysInYear(0)); + $this->assertNull(DateHelper::daysInYear('0')); + $this->assertNull(DateHelper::daysInYear('')); // December 31st 2022 is a Saturday. $value = '2022-12-31 00:00:00'; @@ -201,6 +209,10 @@ public function testDayOfWeek() { // Pass nothing and expect to get NULL. $this->assertNull(DateHelper::dayOfWeek()); + $this->assertNull(DateHelper::dayOfWeek(FALSE)); + $this->assertNull(DateHelper::dayOfWeek(0)); + $this->assertNull(DateHelper::dayOfWeek('0')); + $this->assertNull(DateHelper::dayOfWeek('')); // December 31st 2022 is a Saturday. $value = '2022-12-31 00:00:00'; @@ -219,6 +231,10 @@ public function testDayOfWeekName() { // Pass nothing and expect to get NULL. $this->assertNull(DateHelper::dayOfWeekName()); + $this->assertNull(DateHelper::dayOfWeekName(FALSE)); + $this->assertNull(DateHelper::dayOfWeekName(0)); + $this->assertNull(DateHelper::dayOfWeekName('0')); + $this->assertNull(DateHelper::dayOfWeekName('')); // December 31st 2022 is a Saturday. $value = '2022-12-31 00:00:00';