You are here

public static function PersianDateHelper::weekDaysOrdered in Persian Date for Drupal 8 8

Same name and namespace in other branches
  1. 8.4 src/PersianDateHelper.php \Drupal\persian_date\PersianDateHelper::weekDaysOrdered()

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].

Overrides DateHelper::weekDaysOrdered

File

src/PersianDateHelper.php, line 242

Class

PersianDateHelper

Namespace

Drupal\persian_date

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;
}