Return the events in this site for the given month grouped by week.
553314
def _getEventsByWeek(self, request, year, month):
        
        home = request.site.root_page
        return getAllEventsByWeek(request, year, month, home=home)
806500
function monthCalendar(date) {
    var start = date.clone().startOf("month").startOf("week").startOf("day");
    var end = date.clone().endOf("month").endOf("week").startOf("day");
    var result = [];
    var current = start.weekday(0).subtract(1, "d");
    while (true) {
        current = current.clone().add(1, "d");
        result.push(current);
        if (areDatesEqual(current, end)) {
            break;
        }
    }
    return result;
}
1309824
public function seeWeekInMonth($date, $week) {
        \PHPUnit_Framework_Assert::assertEquals($week, $this->_ParseDate($date)->weekOfMonth);
    }
520683
private SortedSet<WeekOfMonth> readWeeksOfMonth(JSONValue json) {

        JSONArray array = null == json ? null : json.isArray();
        if (null != array) {
            SortedSet<WeekOfMonth> result = new TreeSet<>();
            for (int i = 0; i < array.size(); i++) {
                String weekStr = readOptionalString(array.get(i));
                try {
                    WeekOfMonth week = WeekOfMonth.valueOf(weekStr);
                    result.add(week);
                } catch (@SuppressWarnings("unused") IllegalArgumentException | NullPointerException e) {
                    // Just skip
                }
            }
            return result;
        }
        return new TreeSet<>();
    }
141992
public final void setWeeksOfMonth(SortedSet<WeekOfMonth> weeksOfMonth) {

        m_weeksOfMonth.clear();
        if (null != weeksOfMonth) {
            m_weeksOfMonth.addAll(weeksOfMonth);
        }

    }
1087672
def filter_by_months(self, months):
        
        _filt_values = []
        _filt_datetimes = []
        for i, d in enumerate(self.datetimes):
            if d in months:
                _filt_datetimes.append(d)
                _filt_values.append(self._values[i])
        _filt_header = self.header.duplicate()
        return MonthlyCollection(_filt_header, _filt_values, _filt_datetimes)
940360
private void sortAndCacheEvents(List<? extends WeekViewEvent> events) {
        sortEvents(events);
        for (WeekViewEvent event : events) {
            cacheEvent(event);
        }
    }
434354
function getWeeks(dates) {
  const weeksLength = Math.ceil(dates.length / 7);
  const weeks = [];
  for (let i = 0; i < weeksLength; i++) {
    weeks[i] = [];
    for (let x = 0; x < 7; x++) {
      weeks[i].push(dates[i * 7 + x]);
    }
  }
  return weeks;
}
1359962
def iterweekdays(self, d1, d2):
        
        for dt in self.iterdays(d1, d2):
            if not self.isweekend(dt):
                yield dt
331903
private MonthCellWithMonthIndex getMonthCellWithIndexByDate(Date date) {
    Calendar searchCal = Calendar.getInstance(timeZone, locale);
    searchCal.setTime(date);
    String monthKey = monthKey(searchCal);
    Calendar actCal = Calendar.getInstance(timeZone, locale);

    int index = cells.getIndexOfKey(monthKey);
    List<List<MonthCellDescriptor>> monthCells = cells.get(monthKey);
    for (List<MonthCellDescriptor> weekCells : monthCells) {
      for (MonthCellDescriptor actCell : weekCells) {
        actCal.setTime(actCell.getDate());
        if (sameDate(actCal, searchCal) && actCell.isSelectable()) {
          return new MonthCellWithMonthIndex(actCell, index);
        }
      }
    }
    return null;
  }
849105
def get_dated_items(self):
        
        self.date_list, self.object_list, extra_context = super(
            EntryWeek, self).get_dated_items()
        self.date_list = self.get_date_list(self.object_list, 'day')
        extra_context['week_end_day'] = extra_context[
            'week'] + datetime.timedelta(days=6)
        return self.date_list, self.object_list, extra_context
450671
def fetch_weeks(self, weeks, overwrite=False):
        """"""
        esf = ElasticsearchFetcher(self.store, self.config)
        for year, week in weeks:
            print("Fetch {}-{}".format(year, week))
            esf.fetch(year, week, overwrite)
198748
def get_calendar_entries(context, year=None, month=None,
                         template='zinnia/tags/entries_calendar.html'):
    
    if not (year and month):
        day_week_month = (context.get('day') or
                          context.get('week') or
                          context.get('month'))
        publication_date = getattr(context.get('object'),
                                   'publication_date', None)
        if day_week_month:
            current_month = day_week_month
        elif publication_date:
            if settings.USE_TZ:
                publication_date = timezone.localtime(publication_date)
            current_month = publication_date.date()
        else:
            today = timezone.now()
            if settings.USE_TZ:
                today = timezone.localtime(today)
            current_month = today.date()
        current_month = current_month.replace(day=1)
    else:
        current_month = date(year, month, 1)

    dates = list(map(
        lambda x: settings.USE_TZ and timezone.localtime(x).date() or x.date(),
        Entry.published.datetimes('publication_date', 'month')))

    if current_month not in dates:
        dates.append(current_month)
        dates.sort()
    index = dates.index(current_month)

    previous_month = index > 0 and dates[index - 1] or None
    next_month = index != len(dates) - 1 and dates[index + 1] or None
    calendar = Calendar()

    return {'template': template,
            'next_month': next_month,
            'previous_month': previous_month,
            'calendar': calendar.formatmonth(
                current_month.year,
                current_month.month,
                previous_month=previous_month,
                next_month=next_month)}
1191109
async def get_events(
        self, device_ids, group_ids=None, from_time=None, to_time=None, event_types=None
    ):
        """"""
        if to_time is None:
            to_time = datetime.utcnow()
        if from_time is None:
            from_time = to_time - timedelta(seconds=EVENT_INTERVAL)
        if event_types is None:
            event_types = ["allEvents"]

        get_params = []

        get_params.extend([("deviceId", value) for value in device_ids])
        if group_ids is not None:
            get_params.extend([("groupId", value) for value in group_ids])
        get_params.extend([("from", from_time.isoformat() + "Z")])
        get_params.extend([("to", to_time.isoformat() + "Z")])
        get_params.extend([("type", value) for value in event_types])

        data = await self.api("reports/events", get_params)

        if self.connected and self.authenticated:
            self._events = data
        else:
            self._events = self._events

        return self._events
98981
def blog_months(*args):
    
    dates = BlogPost.objects.published().values_list("publish_date", flat=True)
    date_dicts = [{"date": datetime(d.year, d.month, 1)} for d in dates]
    month_dicts = []
    for date_dict in date_dicts:
        if date_dict not in month_dicts:
            month_dicts.append(date_dict)
    for i, date_dict in enumerate(month_dicts):
        month_dicts[i]["post_count"] = date_dicts.count(date_dict)
    return month_dicts
561640
def events_this_week(context):
    
    request = context['request']
    home = request.site.root_page
    cal = CalendarPage.objects.live().descendant_of(home).first()
    calUrl = cal.get_url(request) if cal else None
    calName = cal.title if cal else None
    today = dt.date.today()
    beginOrd = today.toordinal()
    if today.weekday() != 6:
        # Start week with Monday, unless today is Sunday
        beginOrd -= today.weekday()
    endOrd = beginOrd + 6
    dateFrom = dt.date.fromordinal(beginOrd)
    dateTo   = dt.date.fromordinal(endOrd)
    if cal:
        events = cal._getEventsByDay(request, dateFrom, dateTo)
    else:
        events = getAllEventsByDay(request, dateFrom, dateTo)
    return {'request':      request,
            'today':        today,
            'calendarUrl':  calUrl,
            'calendarName': calName,
            'events':       events }
626927
function(weekBeginDate) {
        var overlaps = false;
        var nextWeek = this.add(weekBeginDate, this.DAY, 6);
        if (nextWeek.getMonth() != weekBeginDate.getMonth()) {
            overlaps = true;
        }
        return overlaps;
    }