Esempio n. 1
0
def all_weekdays(year, month, week, day_of_week):
    dt = date(year, month, 1)

    if week == 'last':
        clean_week = int(-1)
        if month == 1 or month == 3 or month == 5 or month == 7 or month == 8 or month == 10 or month == 12:
            day_offset = 31
        elif month == 2:
            day_offset = 28
        else:
            day_offset = 30
    else:
        clean_week = +int(week.strip("stndrh"))
        day_offset = 0

    if day_of_week == 'Monday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.MO(clean_week))
        return the_date
    elif day_of_week == 'Tuesday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.TU(clean_week))
        return the_date
    elif day_of_week == 'Wednesday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.WE(clean_week))
        return the_date
    elif day_of_week == 'Thursday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.TH(clean_week))
        return the_date
    elif day_of_week == 'Friday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.FR(clean_week))
        return the_date
    elif day_of_week == 'Saturday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.SA(clean_week))
        return the_date
    elif day_of_week == 'Sunday':
        the_date = dt + rdelta.relativedelta(days=day_offset,
                                             weekday=rdelta.SU(clean_week))
        return the_date
def meetup_day(year, month, targetday, targetweek):

    weekdays = dict(zip(list(calendar.day_name), range(7)))
    steps = dict(zip(['1st', '2nd', '3rd', '4th', 'last'], range(7, 36, 7)))
    steps['teenth'] = 19
    targetday = weekdays[targetday]
    getDay = {
        0: relativedelta.MO(-1),
        1: relativedelta.TU(-1),
        2: relativedelta.WE(-1),
        3: relativedelta.TH(-1),
        4: relativedelta.FR(-1),
        5: relativedelta.SA(-1),
        6: relativedelta.SU(-1),
    }

    d = datetime.date(year, month, 1) + relativedelta.relativedelta(
        day=steps[targetweek], weekday=getDay[targetday])
    return d
Esempio n. 3
0
    def get_variable_days(self, year):
        # usual variable days
        days = super().get_variable_days(year)

        days += [
            self.get_veterans_day(year),
            self.get_national_memorial_day(year),
            Holiday(
                date(year, 9, 1) + rd.relativedelta(weekday=rd.MO(1)),
                "Labor Day",
                indication="1st Monday in September",
            ),

            Holiday(
                date(year, 11, 1) + rd.relativedelta(weekday=rd.TH(4)),
                "Thanksgiving Day",
                indication="4th Thursday in November",
            ),
        ]

        # Martin Luther King's Day started only in 1985
        if year >= 1985:
            days.append(self.get_martin_luther_king_day(year))

        if self.include_mardi_gras:
            days.append(self.get_mardi_gras(year))

        if self.include_federal_presidents_day:
            days.append(self.get_presidents_day(year))

        if self.include_lincoln_birthday:
            days.append(self.get_lincoln_birthday(year))

        if self.include_cesar_chavez_day:
            days.extend(self.get_cesar_chavez_days(year))

        if self.include_patriots_day:
            days.append(self.get_patriots_day(year))

        if self.include_columbus_day:
            days.append(self.get_columbus_day(year))

        if self.include_confederation_day:
            days.append(self.get_confederate_day(year))

        if self.include_jefferson_davis_birthday:
            days.append(self.get_jefferson_davis_birthday(year))

        ind = "January 20 (or 21st if Sunday) following an election year"
        if self.include_inauguration_day:
            # Is it a "Inauguration year"?
            if UnitedStates.is_presidential_year(year - 1):
                days.append(
                    Holiday(
                        self.get_inauguration_date(year),
                        "Inauguration Day",
                        indication=ind,
                    ),
                )

        if self.include_election_day_every_year:
            days.append(self.get_election_day(year))
        elif self.include_election_day_even:
            if (year % 2) == 0:
                days.append(self.get_election_day(year))

        if self.include_thanksgiving_friday:
            days.append(
                self.get_thanksgiving_friday(year)
            )

        return days
Esempio n. 4
0
def thu(a):
    thursday = str(today + rdelta.relativedelta(weekday=rdelta.TH(a)))
    output = thursday[8:10] + '/' + thursday[5:7] + '/' + thursday[2:4]
    return output