Get array of narrow textual representation of a day
sorted by first day of week to end.

@param string|int $day (string)Mon through Sun|(int) 1 for Monday through 7

@return array|string
195250
public function getWeekDayNamesNarrow($day = null)
    {
        $calendar = $this->getName();
        // gregorian, generic

        $data = array();
        $calendsFallback = array($calendar, 'gregorian', 'generic');
        foreach ($calendsFallback as $calendar) {
            $data = $this->getRepoReader()->getEntityByPath(
                'dates/calendars/calendar[@type="'.$calendar.'"]/days/dayContext[@type="format"]/dayWidth[@type="abbreviated"]/day'
            );

            if ($data) {
                break;
            }
        }

        $dayOfWeeks = array();
        foreach($data as $d) {
            $dayOfWeeks[$d['type']] = $d['value'];
        }

        $return = ($day == null) ? $dayOfWeeks : false;

        $day = (is_string($day)) ? strtolower($day) : $day;

        if (is_string($day) && isset($dayOfWeeks[$day])) {
            $return = $dayOfWeeks[$day];
        } elseif(is_int($day)) {
            // get with index
            $arrayKeys = array_keys($dayOfWeeks);
            $return    = $dayOfWeeks[$arrayKeys[$day]];
        }

        return $return;
    }
1274684
public static int dayOfWeek(long day) {
        long[] remainder = new long[1];
        floorDivide(day + Calendar.THURSDAY, 7, remainder);
        int dayOfWeek = (int)remainder[0];
        dayOfWeek = (dayOfWeek == 0) ? 7 : dayOfWeek;
        return dayOfWeek;
    }
1347255
private function getClosestDayAfter($dayNumber)
    {
        if (null !== $day = $this->getDay($dayNumber)) {
            return $day;
        }

        return $this->getDayAfter($dayNumber);
    }
194985
public static function all(DayOfWeek $first = null) : array
    {
        $days = [];
        $first = $first ?: DayOfWeek::get(DayOfWeek::MONDAY);
        $current = $first;

        do {
            $days[] = $current;
            $current = $current->plus(1);
        }
        while (! $current->isEqualTo($first));

        return $days;
    }
223715
function(v) {
            var days = v.split(',').map(function(day) {
                var m = day.match(/([+-]?\d)?(SU|MO|TU|WE|TH|FR|SA)/);
                return [parseInt(m[1],10)||0, WKDAYS.indexOf(m[2])];
            });

            days.sort(function(d1, d2) {
                // Sort by week, day of week
                if(d1[0] == d2[0])
                    return d1[1] - d2[1];
                else
                    return d1[0] - d2[0];
            });

            return days;
        }
103826
public function get_starting_weekday() {
        global $CFG;

        if (isset($CFG->calendar_startwday)) {
            $firstday = $CFG->calendar_startwday;
        } else {
            $firstday = get_string('firstdayofweek', 'langconfig');
        }

        if (!is_numeric($firstday)) {
            $startingweekday = CALENDAR_DEFAULT_STARTING_WEEKDAY;
        } else {
            $startingweekday = intval($firstday) % 7;
        }

        return get_user_preferences('calendar_startwday', $startingweekday);
    }
5032
public function dayToString($day, $abbr=false)
  {
    switch ($day)
    {
      case 0:
        return $abbr ? $this->translate('DAY_SUN') : $this->translate('DAY_SUNDAY');
      case 1:
        return $abbr ? $this->translate('DAY_MON') : $this->translate('DAY_MONDAY');
      case 2:
        return $abbr ? $this->translate('DAY_TUE') : $this->translate('DAY_TUESDAY');
      case 3:
        return $abbr ? $this->translate('DAY_WED') : $this->translate('DAY_WEDNESDAY');
      case 4:
        return $abbr ? $this->translate('DAY_THU') : $this->translate('DAY_THURSDAY');
      case 5:
        return $abbr ? $this->translate('DAY_FRI') : $this->translate('DAY_FRIDAY');
      case 6:
        return $abbr ? $this->translate('DAY_SAT') : $this->translate('DAY_SATURDAY');
    }
  }
588383
public function get_weekdays() {
        return array(
            0 => array(
                'shortname' => get_string('sun', 'calendar'),
                'fullname' => get_string('sunday', 'calendar')
            ),
            1 => array(
                'shortname' => get_string('mon', 'calendar'),
                'fullname' => get_string('monday', 'calendar')
            ),
            2 => array(
                'shortname' => get_string('tue', 'calendar'),
                'fullname' => get_string('tuesday', 'calendar')
            ),
            3 => array(
                'shortname' => get_string('wed', 'calendar'),
                'fullname' => get_string('wednesday', 'calendar')
            ),
            4 => array(
                'shortname' => get_string('thu', 'calendar'),
                'fullname' => get_string('thursday', 'calendar')
            ),
            5 => array(
                'shortname' => get_string('fri', 'calendar'),
                'fullname' => get_string('friday', 'calendar')
            ),
            6 => array(
                'shortname' => get_string('sat', 'calendar'),
                'fullname' => get_string('saturday', 'calendar')
            ),
        );
    }
452621
public static function weekdays($num = 1): array
    {
        $days = [];
        $day = self::parse(Date('Y-m-d'));
        while (count($days) < $num) {
            if (!$day->isWeekend()) {
                $days[] = clone $day;
            }
            $day->addWeekday();
        }
        return $days;
    }
1358635
private static function translateToDayNames(string $annotation) : array
	{
		static $workingDays = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri',];
		static $weekend = ['Sat', 'Sun',];

		$days = [];
		foreach (static::splitMultipleValues($annotation) as $value) {
			switch ($value) {
				case 'working days':
					$days = array_merge($days, $workingDays);
					break;
				case 'weekend':
					$days = array_merge($days, $weekend);
					break;
				default:
					$days[] = $value;
					break;
			}
		}

		return array_unique($days);
	}
481896
public function dayToString($day, $abbr = false)
	{
		switch ($day)
		{
			case 0:
				return $abbr ? \Lang::txt('SUN') : \Lang::txt('SUNDAY');
			case 1:
				return $abbr ? \Lang::txt('MON') : \Lang::txt('MONDAY');
			case 2:
				return $abbr ? \Lang::txt('TUE') : \Lang::txt('TUESDAY');
			case 3:
				return $abbr ? \Lang::txt('WED') : \Lang::txt('WEDNESDAY');
			case 4:
				return $abbr ? \Lang::txt('THU') : \Lang::txt('THURSDAY');
			case 5:
				return $abbr ? \Lang::txt('FRI') : \Lang::txt('FRIDAY');
			case 6:
				return $abbr ? \Lang::txt('SAT') : \Lang::txt('SATURDAY');
		}
	}
566943
public static function getWeekdayFullname($day = null)
    {
        if ($day === null) {
            $day = new AnDate();
        }
        if ($day instanceof AnDate) {
            $weekday = self::getDayOfWeek($day);
        } elseif (is_int($day)) {
            $weekday = $day;
        }
        $names = self::getWeekDays();
        return $names[$weekday];
    }
173449
public function getLastDayOfLastWeek()
    {
        $lastDay = clone $this->end;
        $lastDay->sub(new \DateInterval('P1D'));

        return $this->getFactory()->findFirstDayOfWeek($lastDay)->add(new \DateInterval('P6D'));
    }
677526
private static int dayToUtilDay(int day) {
        switch (day) {
            case EventRecurrence.SU: return Calendar.SUNDAY;
            case EventRecurrence.MO: return Calendar.MONDAY;
            case EventRecurrence.TU: return Calendar.TUESDAY;
            case EventRecurrence.WE: return Calendar.WEDNESDAY;
            case EventRecurrence.TH: return Calendar.THURSDAY;
            case EventRecurrence.FR: return Calendar.FRIDAY;
            case EventRecurrence.SA: return Calendar.SATURDAY;
            default: throw new IllegalArgumentException("bad day argument: " + day);
        }
    }
249099
public function dayNames(int $day_number): string
    {
        static $translated_day_names;

        if ($translated_day_names === null) {
            $translated_day_names = [
                0 => I18N::translate('Monday'),
                1 => I18N::translate('Tuesday'),
                2 => I18N::translate('Wednesday'),
                3 => I18N::translate('Thursday'),
                4 => I18N::translate('Friday'),
                5 => I18N::translate('Saturday'),
                6 => I18N::translate('Sunday'),
            ];
        }

        return $translated_day_names[$day_number];
    }
650496
public function day($options = array())
    {
        $options = new AnConfig($options);

        $options->append(array(
            'selected' => null,
            'prompt' => true,
        ));

        $days = array_combine(range(1, 31), range(1, 31));
        $selected = $options->selected;
        unset($options->selected);
        $prompt = $options->prompt;
        unset($options->prompt);
        if ($prompt) {
            $array = array(AnTranslator::_('LIB-AN-SELECTOR-SELECT-DAY'));
            $days = AnHelperArray::merge($array, $days);
        }

        return $this->_html->select($options->name, array('options' => $days, 'selected' => $selected), AnConfig::unbox($options));
    }
1371568
public static function weekends() : array
    {
        $days        = self::getAll();
        $weekEndDays = [];

        foreach ($days as $key => $day) {
            if ($day->isWeekEnd()) {
                $weekEndDays[] = $day;
            }
        }

        return $weekEndDays;
    }