diff --git a/core/lib/Drupal/Core/Datetime/DateHelper.php b/core/lib/Drupal/Core/Datetime/DateHelper.php index 0bc8fdb..130f62b 100644 --- a/core/lib/Drupal/Core/Datetime/DateHelper.php +++ b/core/lib/Drupal/Core/Datetime/DateHelper.php @@ -260,8 +260,16 @@ public static function weekDaysOrdered($weekdays) { $first_day = \Drupal::config('system.date')->get('first_day'); if ($first_day > 0) { for ($i = 1; $i <= $first_day; $i++) { - $last = array_shift($weekdays); - array_push($weekdays, $last); + // Reset the array to the first element. + reset($weekdays); + // Retrieve the first week day value. + $last = current($weekdays); + // Store the corresponding key. + $key = key($weekdays); + // Remove this week day from the beginning of the array. + unset($weekdays[$key]); + // Add this week day to the end of the array. + $weekdays[$key] = $last; } } return $weekdays; diff --git a/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php b/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php new file mode 100644 index 0000000..991a02b --- /dev/null +++ b/core/tests/Drupal/Tests/Core/Datetime/DateHelperTest.php @@ -0,0 +1,111 @@ + ['first_day' => $first_day]]; + $container->set('config.factory', $this->getConfigFactoryStub($config)); + \Drupal::setContainer($container); + + $weekdays = DateHelper::weekDaysUntranslated(); + $this->assertSame($expected, DateHelper::weekDaysOrdered($weekdays)); + } + + public function providerTestWeekDaysOrdered() { + $data = []; + $data[] = [0, [ + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', + ]]; + $data[] = [1, [ + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', + 0 => 'Sunday', + ]]; + $data[] = [2, [ + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', + 0 => 'Sunday', + 1 => 'Monday', + ]]; + $data[] = [3, [ + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + ]]; + $data[] = [4, [ + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + ]]; + $data[] = [5, [ + 5 => 'Friday', + 6 => 'Saturday', + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + ]]; + $data[] = [6, [ + 6 => 'Saturday', + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + ]]; + $data[] = [7, [ + 0 => 'Sunday', + 1 => 'Monday', + 2 => 'Tuesday', + 3 => 'Wednesday', + 4 => 'Thursday', + 5 => 'Friday', + 6 => 'Saturday', + ]]; + return $data; + } + +}