示例#1
0
    def eval(self) -> datetime:
        holiday = self.value[0].eval()
        dttm, country = [None, None]
        if len(self.value) >= 2:
            dttm = self.value[1].eval()
        if len(self.value) == 3:
            country = self.value[2]
        holiday_year = dttm.year if dttm else parse_human_datetime("today").year
        country = country.eval() if country else "US"

        holiday_lookup = CountryHoliday(country, years=[holiday_year], observed=False)
        searched_result = holiday_lookup.get_named(holiday)
        if len(searched_result) == 1:
            return dttm_from_timetuple(searched_result[0].timetuple())
        raise ValueError(_("Unable to find such a holiday: [{}]").format(holiday))
示例#2
0
#!/usr/bin/python3
# Makes the weekly meeting schedule, following some rules:
#  * Recognize a bunch of US-centric holidays and move meeting from Mon -> Tue
#  * Put in special notices when US daylight/standard changes occur
#  * Never hold a meeting from December 23 through December 31 inclusive
import datetime
import sys

import pytz
import icalendar
from holidays import CountryHoliday

hols = CountryHoliday('US', state='NY')
tz = pytz.timezone('US/Eastern')
meeting_duration = datetime.timedelta(seconds=3600)


def localize(d):
    d = tz.localize(d)
    return d


now = localize(datetime.datetime.now())


def first_monday(year):
    d = datetime.datetime(year, 1, 2, 14)
    while d.weekday() != 0:
        d += datetime.timedelta(days=1)
    return d