Reorder the days property based on current language.
3332
private static function init()
    {
        $day = Calendar::getFirstWeekday();
        $day = $day == 0 ? 7 : $day;
        self::$weekStartsAt = $day;

        $days = self::$days;
        while (array_keys($days)[0] != $day) {
            $key = array_keys($days)[0];
            $value = $days[$key];
            unset($days[$key]);
            $days[$key] = $value;
        }

        self::$init = true;
    }
448033
def set_day(self, day: int) -> datetime:
        
        self.value = self.value.replace(day=day)
        return self.value
1349354
def normalize_weekly(data):
    """"""
    if "tblMenu" not in data["result_data"]["Document"]:
        data["result_data"]["Document"]["tblMenu"] = []
    if isinstance(data["result_data"]["Document"]["tblMenu"], dict):
        data["result_data"]["Document"]["tblMenu"] = [data["result_data"]["Document"]["tblMenu"]]
    for day in data["result_data"]["Document"]["tblMenu"]:
        if "tblDayPart" not in day:
            continue
        if isinstance(day["tblDayPart"], dict):
            day["tblDayPart"] = [day["tblDayPart"]]
        for meal in day["tblDayPart"]:
            if isinstance(meal["tblStation"], dict):
                meal["tblStation"] = [meal["tblStation"]]
            for station in meal["tblStation"]:
                if isinstance(station["tblItem"], dict):
                    station["tblItem"] = [station["tblItem"]]
    return data
615283
def SetWeekdayService(self, has_service=True):
    """"""
    for i in range(0, 5):
      self.SetDayOfWeekHasService(i, has_service)
288510
def locale(self, value):
        """"""
        if not isinstance(value, Locale):
            value = Locale.parse(value)
        self.local.babel_locale = value
361927
def refresh(self):
        
        self.setDirty(False)
        self.blockSignals(True)
        self.setUpdatesEnabled(False)
        self.clear()
        
        locales = self._availableLocales
        if not locales:
            locales = self.allLocales()
        
        if not self.showLanguage():
            if self.isTranslated():
                sorter = lambda x: x.get_territory_name(base)
            else:
                sorter = lambda x: x.get_territory_name()
        else:
            if self.isTranslated():
                sorter = lambda x: x.get_language_name(base)
            else:
                sorter = lambda x: x.get_language_name()
        
        locales = sorted(locales, key=sorter)
        index = 0
        for i, locale in enumerate(locales):
            babel_locale = babel.Locale.parse(locale)
            code = '{0}_{1}'.format(babel_locale.language,
                                    babel_locale.territory)
            keys = {}
            if self.isTranslated():
                keys['lang'] = babel_locale.get_language_name(base)
                keys['territory'] = babel_locale.get_territory_name(base)
                keys['script'] = babel_locale.get_script_name(base)
            else:
                keys['lang'] = babel_locale.get_language_name()
                keys['territory'] = babel_locale.get_territory_name()
                keys['script'] = babel_locale.get_script_name()
            
            if self.showLanguage():
                opts = ''
                if self.showScriptName() and keys['script']:
                    opts += keys['script']
                if self.showTerritory() and keys['territory']:
                    if opts:
                        opts += ', '
                    opts += keys['territory']
                if opts:
                    opts = ' (' + opts + ')'
                
                label = keys['lang'] + opts
                
            elif self.showTerritory():
                label = keys['territory']
            else:
                label = code
            
            self.addItem(label)
            self.setItemData(i, wrapVariant(str(code)))
            
            name = babel_locale.territory.lower()
            ico = 'img/flags/{0}.png'.format(name)
            flag = QtGui.QIcon(resources.find(ico))
            if flag.isNull():
                ico = 'img/flags/_United Nations.png'
                flag = QtGui.QIcon(resources.find(ico))
            
            self.setItemIcon(i, flag)
            if code == self.baseLocale():
                index = i
        
        self.setCurrentIndex(index)
        self.setUpdatesEnabled(True)
        self.blockSignals(False)
1220506
def ordered(self, ord='desc'):
        """"""
        if ord not in ('asc', 'desc', ):
            raise
        ord_f = getattr(PIDRelation.index, ord)()
        return self.order_by(ord_f)
222103
private function setDaysOfWeekNames()
    {
        if (empty($this->pluginOptions['locale']['daysOfWeek'])) {
            $this->pluginOptions['locale']['daysOfWeek'] = Yii::app()->locale->getWeekDayNames('narrow', true);
        }
    }
1067604
def _to_desired_dates(self, arr):
        """"""
        times = utils.times.extract_months(
            arr[internal_names.TIME_STR], self.months
        )
        return arr.sel(time=times)
378859
def OnReorder(self, event):
        """"""
        column = self.columns[event.GetColumn()]
        return self.ReorderByColumn( column )
69894
def replace(self, year=None, month=None, day=None, hour=None,
                minute=None, second=None, microsecond=None, tzinfo=True):
        """"""
        if year is None:
            year = self.year
        if month is None:
            month = self.month
        if day is None:
            day = self.day
        if hour is None:
            hour = self.hour
        if minute is None:
            minute = self.minute
        if second is None:
            second = self.second
        if microsecond is None:
            microsecond = self.microsecond
        if tzinfo is True:
            tzinfo = self.tzinfo
        _check_date_fields(year, month, day)
        _check_time_fields(hour, minute, second, microsecond)
        _check_tzinfo_arg(tzinfo)
        return datetime(year, month, day, hour, minute, second,
                          microsecond, tzinfo)
653558
function updateDate(d, params, reset, advance, prefer, weekdayDir, contextDate) {
  var upperUnitIndex;

  function setUpperUnit(unitName, unitIndex) {
    if (prefer && !upperUnitIndex) {
      if (unitName === 'weekday') {
        upperUnitIndex = WEEK_INDEX;
      } else {
        upperUnitIndex = getHigherUnitIndex(unitIndex);
      }
    }
  }

  function setSpecificity(unitIndex) {
    // Other functions may preemptively set the specificity before arriving
    // here so concede to them if they have already set more specific units.
    if (unitIndex > params.specificity) {
      return;
    }
    params.specificity = unitIndex;
  }

  function canDisambiguate() {
    if (!upperUnitIndex || upperUnitIndex > YEAR_INDEX) {
      return;
    }

    switch(prefer) {
      case -1: return d >= (contextDate || getNewDate());
      case  1: return d <= (contextDate || getNewDate());
    }
  }

  function disambiguateHigherUnit() {
    var unit = DateUnits[upperUnitIndex];
    advance = prefer;
    setUnit(unit.name, 1, unit, upperUnitIndex);
  }

  function handleFraction(unit, unitIndex, fraction) {
    if (unitIndex) {
      var lowerUnit = DateUnits[getLowerUnitIndex(unitIndex)];
      var val = round(unit.multiplier / lowerUnit.multiplier * fraction);
      params[lowerUnit.name] = val;
    }
  }

  function monthHasShifted(d, targetMonth) {
    if (targetMonth < 0) {
      targetMonth = targetMonth % 12 + 12;
    }
    return targetMonth % 12 !== getMonth(d);
  }

  function setUnit(unitName, value, unit, unitIndex) {
    var method = unit.method, checkMonth, fraction;

    setUpperUnit(unitName, unitIndex);
    setSpecificity(unitIndex);

    fraction = value % 1;
    if (fraction) {
      handleFraction(unit, unitIndex, fraction);
      value = trunc(value);
    }

    if (unitName === 'weekday') {
      if (!advance) {
        // Weekdays are always considered absolute units so simply set them
        // here even if it is an "advance" operation. This is to help avoid
        // ambiguous meanings in "advance" as well as to neatly allow formats
        // like "Wednesday of next week" without more complex logic.
        setWeekday(d, value, weekdayDir);
      }
      return;
    }
    checkMonth = unitIndex === MONTH_INDEX && getDate(d) > 28;

    // If we are advancing or rewinding, then we need we need to set the
    // absolute time if the unit is "hours" or less. This is due to the fact
    // that setting by method is ambiguous during DST shifts. For example,
    // 1:00am on November 1st 2015 occurs twice in North American timezones
    // with DST, the second time being after the clocks are rolled back at
    // 2:00am. When springing forward this is automatically handled as there
    // is no 2:00am so the date automatically jumps to 3:00am. However, when
    // rolling back, setHours(2) will always choose the first "2am" even if
    // the date is currently set to the second, causing unintended jumps.
    // This ambiguity is unavoidable when setting dates as the notation is
    // ambiguous. However when advancing, we clearly want the resulting date
    // to be an acutal hour ahead, which can only be accomplished by setting
    // the absolute time. Conversely, any unit higher than "hours" MUST use
    // the internal set methods, as they are ambiguous as absolute units of
    // time. Years may be 365 or 366 days depending on leap years, months are
    // all over the place, and even days may be 23-25 hours depending on DST
    // shifts. Finally, note that the kind of jumping described above will
    // occur when calling ANY "set" method on the date and will occur even if
    // the value being set is identical to the one currently set (i.e.
    // setHours(2) on a date at 2am may not be a noop). This is precarious,
    // so avoiding this situation in callDateSet by checking up front that
    // the value is not the same before setting.
    if (advance && !unit.ambiguous) {
      d.setTime(d.getTime() + (value * advance * unit.multiplier));
      return;
    } else if (advance) {
      if (unitIndex === WEEK_INDEX) {
        value *= 7;
        method = DateUnits[DAY_INDEX].method;
      }
      value = (value * advance) + callDateGet(d, method);
    }
    callDateSetWithWeek(d, method, value, advance);
    if (checkMonth && monthHasShifted(d, value)) {
      // As we are setting the units in reverse order, there is a chance that
      // our date may accidentally traverse into a new month, such as setting
      // { month: 1, date 15 } on January 31st. Check for this here and reset
      // the date to the last day of the previous month if this has happened.
      setDate(d, 0);
    }
  }

  if (isNumber(params) && advance) {
    // If param is a number and advancing, the number is in milliseconds.
    params = { millisecond: params };
  } else if (isNumber(params)) {
    // Otherwise just set the timestamp and return.
    d.setTime(params);
    return d;
  }

  iterateOverDateParams(params, setUnit);

  if (reset && params.specificity) {
    resetLowerUnits(d, params.specificity);
  }

  // If past or future is preferred, then the process of "disambiguation" will
  // ensure that an ambiguous time/date ("4pm", "thursday", "June", etc.) will
  // be in the past or future. Weeks are only considered ambiguous if there is
  // a weekday, i.e. "thursday" is an ambiguous week, but "the 4th" is an
  // ambiguous month.
  if (canDisambiguate()) {
    disambiguateHigherUnit();
  }
  return d;
}
981836
def SetNewOrder( self, column ):
        """"""
        if column.sortOn:
            # multiple sorts for the click...
            columns = [self.columnByAttribute(attr) for attr in column.sortOn]
            diff = [(a, b) for a, b in zip(self.sortOrder, columns)
                    if b is not a[1]]
            if not diff:
                self.sortOrder[0] = (not self.sortOrder[0][0], column)
            else:
                self.sortOrder = [
                    (c.defaultOrder, c) for c in columns
                ] + [(a, b) for (a, b) in self.sortOrder if b not in columns]
            return False
        else:
            if column is self.sortOrder[0][1]:
                # reverse current major order
                self.sortOrder[0] = (not self.sortOrder[0][0], column)
            else:
                self.sortOrder = [(column.defaultOrder, column)] + [
                    (a, b)
                    for (a, b) in self.sortOrder if b is not column
                ]
            return True
859715
def reorder(self, dst_order, arr, src_order=None):
        """"""
        if dst_order is None:
            dst_order = self.viewer.rgb_order
        if src_order is None:
            src_order = self.rgb_order
        if src_order != dst_order:
            arr = trcalc.reorder_image(dst_order, arr, src_order)

        return arr
1244069
def reorder_keys(self, keys):
        ''''''
        if len(keys) != len(self._set):
            raise ValueError('The supplied number of keys does not match.')
        if set(keys) != self._set:
            raise ValueError('The supplied keys do not match the current set of keys.')
        self._keys = list(keys)
326262
def search_weekday(weekday, jd, direction, offset):
    ''''''
    return weekday_before(weekday, jd + (direction * offset))
1011377
def move(self, dst):
        """"""
        shutil.move(self, dst)
        self = PathStr(dst).join(self.basename())
        return self