DateHelper::weekDaysOrdered

public static DateHelper::weekDaysOrdered($weekdays)

Reorders weekdays to match the first day of the week.

Parameters

array $weekdays: An array of weekdays.

Return value

array An array of weekdays reordered to match the first day of the week. The keys will remain unchanged. For example, if the first day of the week is set to be Monday, the array keys will be [1, 2, 3, 4, 5, 6, 0].

File

core/lib/Drupal/Core/Datetime/DateHelper.php, line 258

Class

DateHelper
Defines Gregorian Calendar date values.

Namespace

Drupal\Core\Datetime

Code

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++) {
      // 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;
}
doc_Drupal
2016-10-29 09:00:51
Comments
Leave a Comment

Please login to continue.