Analog of :func:`check_agency` for ``feed.calendar_dates``.
335594
def check_calendar_dates(
    feed: "Feed", *, as_df: bool = False, include_warnings: bool = False
) -> List:
    
    table = "calendar_dates"
    problems = []

    # Preliminary checks
    if feed.calendar_dates is None:
        return problems

    f = feed.calendar_dates.copy()
    problems = check_for_required_columns(problems, table, f)
    if problems:
        return format_problems(problems, as_df=as_df)

    if include_warnings:
        problems = check_for_invalid_columns(problems, table, f)

    # Check service_id
    problems = check_column(problems, table, f, "service_id", valid_str)

    # Check date
    problems = check_column(problems, table, f, "date", valid_date)

    # No duplicate (service_id, date) pairs allowed
    cond = f[["service_id", "date"]].duplicated()
    problems = check_table(
        problems, table, f, cond, "Repeated pair (service_id, date)"
    )

    # Check exception_type
    v = lambda x: x in [1, 2]
    problems = check_column(problems, table, f, "exception_type", v)

    return format_problems(problems, as_df=as_df)
964357
def verify_month(self, now):
        ''''''
        return self.month == "*" or str(now.month) in self.month.split(" ")
508641
def scheduled_event_trigger(self, event_type):
        """"""
        def callback(when, **kwargs):
            self.queued_scheduled_events.append((when, event_type(when=when, **kwargs)))
        return callback
1179788
def _occursOn(self, myDate):
        
        # TODO analyse which is faster (rrule or db) and test that first
        if myDate not in self.repeat:
            return False
        if CancellationPage.events.child_of(self)                            \
                           .filter(except_date=myDate).exists():
            return False
        return True
465216
def get_date_type(calendar):
    """"""
    try:
        import cftime
    except ImportError:
        raise ImportError(
            'cftime is required for dates with non-standard calendars')
    else:
        calendars = {
            'noleap': cftime.DatetimeNoLeap,
            '360_day': cftime.Datetime360Day,
            '365_day': cftime.DatetimeNoLeap,
            '366_day': cftime.DatetimeAllLeap,
            'gregorian': cftime.DatetimeGregorian,
            'proleptic_gregorian': cftime.DatetimeProlepticGregorian,
            'julian': cftime.DatetimeJulian,
            'all_leap': cftime.DatetimeAllLeap,
            'standard': cftime.DatetimeGregorian
        }
        return calendars[calendar]
499328
def chk_date_arg(s):
    """"""
    if re_date.search(s) is None:
        return False
    comp = s.split('-')
    try:
        dt = datetime.date(int(comp[0]), int(comp[1]), int(comp[2]))
        return True
    except Exception as e:
        return False
982851
def verify_weekday(self, now):
        ''''''
        return self.weekdays == "*" or str(now.weekday()) in self.weekdays.split(" ")
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 }
455699
private void checkDates() {
		DateTime created = this.dateCreated;
		DateTime published = this.datePublished;
		DateTime modified = this.dateModified;
		DateTime reviewed = this.dateReviewed;
		if(
			created != null
			&& published != null
			&& published.compareTo(created) < 0
		) throw new IllegalArgumentException("published may not be before created");
		if(
			created != null
			&& modified != null
			&& modified.compareTo(created) < 0
		) throw new IllegalArgumentException("modified may not be before created");
		if(
			created != null
			&& reviewed != null
			&& reviewed.compareTo(created) < 0
		) throw new IllegalArgumentException("reviewed may not be before created");
	}
169268
function byday(rules, dt, after) {
    if(!rules || !rules.length) return dt;

    // Generate a list of candiDATES. (HA!)
    var candidates = rules.map(function(rule) {
        // Align on the correct day of the week...
        var days = rule[1]-wkday(dt);
        if(days < 0) days += 7;
        var newdt = add_d(new Date(dt), days);

        if(rule[0] > 0) {
            var wk = 0 | ((d(newdt) - 1) / 7) + 1;
            if(wk > rule[0]) return null;

            add_d(newdt, (rule[0] - wk) * 7);
        }
        else if(rule[0] < 0) {
            // Find all the matching days in the month...
            var dt2 = new Date(newdt);
            var days = [];
            while(m(dt2) === m(newdt)) {
                days.push(d(dt2));
                add_d(dt2, 7);
            }

            // Then grab the nth from the end...
            set_d(newdt, days.reverse()[(-rule[0])-1]);
        }

        // Ignore if it's a past date...
        if (newdt.valueOf() <= after.valueOf()) return null;

        return newdt;
    });

    // Select the date occurring next...
    var newdt = sort_dates(candidates).shift();
    return newdt || dt;
}
1070750
def check_due(self):
        """"""
        if self.disabled:
            return False
        if self.is_running:
            return False
        if self.delta is None:
            return False
        last_run = self.last_run
        if last_run is None:
            return True
        now = datetime.utcnow()
        if now > last_run + self.delta:
            return True
        return False
739690
def _process_parse_dates_argument(parse_dates):
    """"""
    # handle non-list entries for parse_dates gracefully
    if parse_dates is True or parse_dates is None or parse_dates is False:
        parse_dates = []

    elif not hasattr(parse_dates, '__iter__'):
        parse_dates = [parse_dates]
    return parse_dates
456853
def _dates(self, key, value):
    
    if value.get('q'):
        self['date_proposed'] = normalize_date(value['q'])
    if value.get('r'):
        self['date_approved'] = normalize_date(value['r'])
    if value.get('s'):
        self['date_started'] = normalize_date(value['s'])
    if value.get('c'):
        self['date_cancelled'] = normalize_date(value['c'])
    if value.get('t'):
        self['date_completed'] = normalize_date(value['t'])

    raise IgnoreKey
112151
def biweekly(date=datetime.date.today()):
    
    return datetime.date(date.year, date.month, 1 if date.day < 15 else 15)
1062634
def onOffset(self, date):
        """"""
        return date.day == _days_in_month(date) and date.month == self.month
1097284
def make_eventrule(date_rule, time_rule, cal, half_days=True):
    
    _check_if_not_called(date_rule)
    _check_if_not_called(time_rule)

    if half_days:
        inner_rule = date_rule & time_rule
    else:
        inner_rule = date_rule & time_rule & NotHalfDay()

    opd = OncePerDay(rule=inner_rule)
    # This is where a scheduled function's rule is associated with a calendar.
    opd.cal = cal
    return opd
1101932
def _getEventsOnDay(self, request, day):
        """"""
        return getAllEventsByDay(request, day, day, home=self)[0]