Sorts the delivery collection by earliest delivery date
502719
public function sortDeliveries(): self
    {
        $this->sort(function (Delivery $a, Delivery $b) {
            if ($a->getLocation() !== $b->getLocation()) {
                return -1;
            }

            return $a->getDeliveryDate()->getEarliest() > $b->getDeliveryDate()->getEarliest();
        });

        return $this;
    }
88915
def _list(self, foldername="INBOX", reverse=False, since=None):
        
        folder = self.folder \
            if foldername == "INBOX" \
            else self._getfolder(foldername)

        def sortcmp(d):
            try:
                return d[1].date
            except:
                return -1

        lst = folder.items() if not since else folder.items_since(since)
        sorted_lst = sorted(lst, key=sortcmp, reverse=1 if reverse else 0)
        itemlist = [(folder, key, msg) for key,msg in sorted_lst]
        return itemlist
379882
def where_earliest(cls, user_id):
        
        return cls.query.filter_by(user_id=user_id)\
            .order_by(cls.created_at.asc()).first()
1130581
def query_order(self, status=None, begintime=None, endtime=None):
        
        return self._post(
            'merchant/order/getbyfilter',
            data={
                'status': status,
                'begintime': begintime,
                'endtime': endtime
            }
        )
1329382
def last(self, count=1):
        
        if self._order_with:
            order = self._order_with.values()[0]
            order = "desc" if order == "asc" else "asc"
            order_with = self._order_with
            self._order_with = {}
            result = self.order_by(**{order_with.keys()[0]: order}).first(count)
            self._order_with = order_with
            return result
        else:
            return self.order_by(id="desc").first(count)
133806
def orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld):
        """"""
        return _swigibpy.EWrapper_orderStatus(self, orderId, status, filled, remaining, avgFillPrice, permId, parentId, lastFillPrice, clientId, whyHeld)
1303475
def _last(self, **spec):
        
        for record in self._entries(spec).order_by(orm.desc(model.Entry.local_date),
                                                   orm.desc(model.Entry.id))[:1]:
            return entry.Entry(record)
        return None
825812
def arrangeByType(service_list, preferred_types):
    """"""

    def enumerate(elts):
        """Return an iterable that pairs the index of an element with
        that element.

        For Python 2.2 compatibility"""
        return zip(range(len(elts)), elts)

    def bestMatchingService(service):
        """Return the index of the first matching type, or something
        higher if no type matches.

        This provides an ordering in which service elements that
        contain a type that comes earlier in the preferred types list
        come before service elements that come later. If a service
        element has more than one type, the most preferred one wins.
        """
        for i, t in enumerate(preferred_types):
            if preferred_types[i] in service.type_uris:
                return i

        return len(preferred_types)

    # Build a list with the service elements in tuples whose
    # comparison will prefer the one with the best matching service
    prio_services = [(bestMatchingService(s), orig_index, s)
                     for (orig_index, s) in enumerate(service_list)]
    prio_services.sort()

    # Now that the services are sorted by priority, remove the sort
    # keys from the list.
    for i in range(len(prio_services)):
        prio_services[i] = prio_services[i][2]

    return prio_services
109797
def _first(self, **spec):
        
        for record in self._entries(spec).order_by(model.Entry.local_date,
                                                   model.Entry.id)[:1]:
            return entry.Entry(record)
        return None
859845
def group_order(tlist):
    """"""
    tidx, token = tlist.token_next_by(t=T.Keyword.Order)
    while token:
        pidx, prev_ = tlist.token_prev(tidx)
        if imt(prev_, i=sql.Identifier, t=T.Number):
            tlist.group_tokens(sql.Identifier, pidx, tidx)
            tidx = pidx
        tidx, token = tlist.token_next_by(t=T.Keyword.Order, idx=tidx)
915795
def _entries_sorted(self):
        """"""
        return sorted(self.entries.values(), key=lambda e: (e.path, e.stage))
895258
async def sort(self, request, reverse=False):
        """"""
        return sorted(
            self.collection, key=lambda o: getattr(o, self.columns_sort, 0), reverse=reverse)
504803
def order_by(self, order_by: Union[set, str]):
        """"""
        clone = self._clone()
        if isinstance(order_by, str):
            order_by = {order_by}

        clone._order_by = clone._order_by.union(order_by)

        return clone
458505
private static Sort first(String columnName, Sort.Order order) {
        return Sort.on(columnName, order);
    }
1178959
function orderByParam(query) {
  const value = query[orderedBy];

  switch (value) {
  case orderByKey:
    return;

  case orderByValue:
    return '$value';

  case orderByPriority:
    return '$priority';

  default:
    return value;
  }
}
1340013
def sales_for_time_period(from_date, to_date):
    
    sales = Order.objects.filter(
        Q(payment_date__lte=to_date) & Q(payment_date__gte=from_date)
    ).exclude(status=Order.CANCELLED)

    return sales
671802
function sortPostsByPublishedDate (pPosts) {
    if (! (pPosts instanceof Array) ) {
        throw new MeowError ("pPosts is not an array");
    }

    pPosts.sort(function (pFirst, pSecond) {
        pFirst = pFirst || {};
        pSecond = pSecond || {};
        var pFirstPublishedDate  = pFirst['published-date'],
            pSecondPublishedDate = pSecond['published-date'];

        if (moment(pFirstPublishedDate).isAfter(pSecondPublishedDate)) {
            return -1;
        }
        else if (moment(pFirstPublishedDate).isBefore(pSecondPublishedDate)) {
            return 1;
        }
        else {
            return pFirst.title.localeCompare(pSecond.title);
        }
    });
    return pPosts;
}