Exemple #1
0
def get_holidays(year, place=['Brazil', None, None], scope='legal', _=str):
    """Returns Brazilian holiday dates. Election dates are also considered
    holidays and they always happen on Sundays.
    """
    adict = {
        date(year,  1,  1): 'Confraternização Universal',
        date(year,  4, 21): 'Tiradentes',
        date(year,  5,  1): 'Dia do trabalhador',
        date(year,  9,  7): 'Dia da Independência',
        date(year, 10, 12): 'Nossa Senhora Aparecida',
        date(year, 11,  2): 'Finados',
        date(year, 11, 15): 'Proclamação da República',
        date(year, 12, 25): 'Natal',
        }  # These are the *national* holidays.

    if place[1] in ('SP', 'São Paulo'):  # State of São Paulo
        adict[date(year, 7, 9)] = 'Revolução Constitucionalista de 1932'

    if place[2] == 'São Paulo':  # City of São Paulo
        eastr = easter.easter(year)
        adict[date(year, 1, 25)] = 'Aniversário da Cidade de São Paulo'
        adict[_carnival(eastr)] = 'Carnaval'
        adict[date(year, 11, 20)] = 'Dia da Consciência Negra'
        adict[eastr - timedelta(days=2)] = 'Sexta-feira da Paixão'
        adict[eastr] = 'Páscoa'
        adict[eastr + timedelta(days=60)] = 'Corpus Christi'
    return adict  # What? You don't celebrate Villa-Lobos' birthday???
Exemple #2
0
    def holidays(self, year):
        hols = super(CzechLocale, self).holidays(year)
        hols.append(date(year, 1, 1))
        hols.append(date(year, 5, 1))
        hols.append(date(year, 5, 8))
        hols.append(date(year, 7, 5))
        hols.append(date(year, 7, 6))
        hols.append(date(year, 9, 28))
        hols.append(date(year, 10, 28))
        hols.append(date(year, 11, 17))
        hols.append(date(year, 12, 24))
        hols.append(date(year, 12, 25))
        hols.append(date(year, 12, 26))

        hols.append( easter(year) + timedelta(days=1))
        if year >= 2016:
            hols.append( easter(year) + timedelta(days=-2))
        return hols
    def get_easter(self) -> dict:
        #Easter Calculation
        easter_day = easter(year=self.this_year, method=3)
        holiday = {str(easter_day): "Easter"}

        #Good Friday Calculation
        good_friday = easter_day - timedelta(days = 2)
        holiday[str(good_friday)] = "Good Friday"

        return holiday
Exemple #4
0
    def holidays(self, year):
        hols = super(SlovakLocale, self).holidays(year)
        hols.append(date(year, 1, 1))
        hols.append(date(year, 1, 6))
        hols.append(date(year, 5, 1))
        hols.append(date(year, 5, 8))
        hols.append(date(year, 7, 5))
        hols.append(date(year, 8, 29))
        hols.append(date(year, 9, 1))
        hols.append(date(year, 9, 15))
        hols.append(date(year, 11, 1))
        hols.append(date(year, 11, 17))
        hols.append(date(year, 12, 24))
        hols.append(date(year, 12, 25))
        hols.append(date(year, 12, 26))

        hols.append(easter(year) + timedelta(days=-2))
        hols.append(easter(year) + timedelta(days=1))
        return hols
def get_holiday():
    """Return today's holiday.

    US Holidays include:
    - New Year's Day
    - Martin Luther King, Jr. Day
    - Washington's Birthday
    - Memorial Day
    - Independence Day
    - Labor Day
    - Columbus Day
    - Veterans Day
    - Thanksgiving
    - Christmas Day

    https://pypi.python.org/pypi/holidays
    """
    now = timezone.localtime(timezone.now())
    today = now.date()
    year = today.year
    us_holidays = holidays.US(years=year)
    us_holidays.observed = False
    us_holidays.append({
        date(year, 2, 2): 'Groundhog Day',
        date(year, 2, 14): 'Valentine\'s Day',
        date(year, 3, 14): 'Pi Day',
        date(year, 3, 17): 'St. Patrick\'s Day',
        date(year, 4, 1): 'April Fools\' Day',
        date(year, 4, 22): 'Earth Day',
        date(year, 5, 4): 'Star Wars Day: May the Fourth Be With You',
        date(year, 5, 5): 'Cinco de Mayo',
        date(year, 6, 14): 'Flag Day',
        date(year, 9, 19): 'International Talk Like a Pirate Day',
        date(year, 10, 21): 'Back to the Future Day',
        date(year, 10, 31): 'Halloween',
        date(year, 12, 24): 'Christmas Eve',
        date(year, 12, 31): 'New Year\'s Eve',
        date(year, 5, 1) + rd(weekday=SU(+2)): 'Mother\'s Day',
        date(year, 6, 1) + rd(weekday=SU(+3)): 'Father\'s Day',
        date(year, 4, 30) + rd(weekday=FR(-1)): 'Arbor Day',
        easter(year): 'Easter',
    })
    if year % 2 == 0:
        us_holidays.append({
            date(year, 11, 1) + rd(weekday=MO) + rd(days=+1): 'Election Day',
        })
    try:
        holiday = us_holidays[today]
    except KeyError:
        return None
    return {
        'icon': holiday_icons.get(holiday, None),
        'name': holiday,
        'date': today,
    }
Exemple #6
0
def easter_day(year):
    d = easter(year)
    r = {'name': 'Easter'}
    r['date'] = datetime(int(year), int(MAR), d.day, now.hour, now.minute)
    r['desc'] = """
                Easter or Resurrection Sunday is a festival and holiday celebrating the Resurrection of Jesus Christ
                from the dead, which occurred three days after his crucifixion.
                """
    r['alt_names'] = 'resurrection-sunday'
    r['link'] = 'http://en.wikipedia.org/wiki/Easter'
    r['link_title'] = 'Wikipedia'
    return r
Exemple #7
0
def all_easter(start, end):
    """Returns all the Easter days between start and end.

    example:
    >>> import datetime
    >>> from datetime import date
    >>> all_easter(date(2012, 1, 1), date(2013, 12, 30))
    [datetime.date(2012, 4, 8), datetime.date(2013, 3, 31)]
    """
    easters = [easter.easter(year) for year in
               xrange(start.year, end.year+1)]
    return [d for d in easters if start <= d <= end]
Exemple #8
0
    def apply(self, other):
        currentEaster = easter(other.year)
        currentEaster = datetime(
            currentEaster.year, currentEaster.month, currentEaster.day)
        currentEaster = tslib._localize_pydatetime(currentEaster, other.tzinfo)

        # NOTE: easter returns a datetime.date so we have to convert to type of
        # other
        if self.n >= 0:
            if other >= currentEaster:
                new = easter(other.year + self.n)
            else:
                new = easter(other.year + self.n - 1)
        else:
            if other > currentEaster:
                new = easter(other.year + self.n + 1)
            else:
                new = easter(other.year + self.n)

        new = datetime(new.year, new.month, new.day, other.hour,
                       other.minute, other.second, other.microsecond)
        return new
Exemple #9
0
def all_boxing(start, end):
    """Returns all boxing days between start and end.

    example:
    >>> import datetime
    >>> from datetime import date
    >>> all_boxing(date(2012, 1, 1), date(2013, 12, 30))
    [datetime.date(2012, 4, 9), datetime.date(2013, 4, 1)]
    """
    one_day = datetime.timedelta(days=1)
    boxings = [easter.easter(year)+one_day for year in
               xrange(start.year, end.year+1)]
    return [d for d in boxings if start <= d <= end]
Exemple #10
0
 def add_duration(unit, orig, value):
     if orig is None:
         return None
     if unit.value == 's':
         return orig + datetime.timedelta(seconds=value)
     if unit.value == 'm':
         return orig + datetime.timedelta(minutes=value)
     if unit.value == 'h':
         return orig + datetime.timedelta(hours=value)
     if unit.value == 'D':
         return orig + datetime.timedelta(days=value)
     if unit.value == 'W':
         return orig + datetime.timedelta(days=value * 7)
     day = orig.day
     while True:
         year = orig.year
         try:
             if unit.value == 'M':
                 m = orig.month + value
                 while m > 12:
                     m -= 12
                     year += 1
                 while m < 1:
                     m += 12
                     year -= 1
                 return orig.replace(month=m, day=day, year=year)
             if unit.value == 'Y':
                 return orig.replace(year=orig.year + value, day=day)
             if unit.value == 'E':
                 offset = orig - easter(year)
                 return easter(year+value) + offset
             raise Exception("Invalid DurationUnit %s" % unit)
         except ValueError:
             if day > 28:
                 day -= 1
             else:
                 raise
def is_easter(current_date):
    easter_date = easter.easter(current_date.year)
    good_friday = easter_date - timedelta(2)
    easter_monday = easter_date + timedelta(1)
    result = None
    if good_friday == current_date:
        result = result or {}
        result['good_friday'] = True
    if easter_monday == current_date:
        result = result or {}
        result['easter_monday'] = True
    if good_friday <= current_date <= easter_monday:
        result = result or {}
        result['easter'] = True
    return result
Exemple #12
0
def is_holiday_poland(day: date):
    est = easter(day.year)
    return day in [
        parse_formatted_date('{0}-01-01'.format(day.year)),
        parse_formatted_date('{0}-01-06'.format(day.year)),
        parse_formatted_date('{0}-05-01'.format(day.year)),
        parse_formatted_date('{0}-05-03'.format(day.year)),
        parse_formatted_date('{0}-08-15'.format(day.year)),
        parse_formatted_date('{0}-11-01'.format(day.year)),
        parse_formatted_date('{0}-11-11'.format(day.year)),
        parse_formatted_date('{0}-12-25'.format(day.year)),
        parse_formatted_date('{0}-12-26'.format(day.year)),
        est + timedelta(days=1),
        est + timedelta(days=60)
    ]
Exemple #13
0
    def _data_anual_movel_em(self, ano):
        """
        Retorna a data anual móvel no ano fornecido.

        Assume que o feriado é anual móvel.

        Esse método deve ser usado internamente.

        Argumentos:
            - ano: um inteiro; o ano consultado.
        """
        return eval(self.data_anual_movel, {
            "pascoa": easter.easter(ano),
            "d": timedelta,
        })
Exemple #14
0
 def render_macro(self, req, name, args):
     if args == None: args = ''
     args = [x.strip() for x in args.split(',')]
     
     year = datetime.date.today().year
     method = 3
     if len(args) >= 1 and args[0] != '':
         year = int(args[0])
     if len(args) >= 2:
         method = int(args[1])
         
     output = str(easter(year, method))
     
     def random_egg():
         return "<img src='%s/egg_0%s.gif' />" % (self.env.href.chrome('easter','img'),random.randint(1,4))
         
     return random_egg() + output + random_egg()
def get_holidays(year, place=['United Kingdom', None, None], scope='legal',
                 _=str):
    """Returns UK holiday dates (legally considered non-working days)."""
    easter_sunday = easter.easter(year)
    return {
        date(year, 1, 1): _('New Year'),
        easter_sunday - timedelta(days=2): _('Good Friday'),
        easter_sunday: _('Easter Sunday'),
        easter_sunday + timedelta(days=1): _('Easter Monday'),
        date(year, 5, 1) + relativedelta(weekday=MO):
        _('Early May Bank Holiday'),  # First Monday of May
        date(year, 5, 31) + relativedelta(weekday=MO(-1)):
        _('Spring Bank Holiday'),  # Last Monday of May
        date(year, 8, 31) + relativedelta(weekday=MO(-1)):
        _('Summer Bank Holiday'),  # Last Monday of August
        date(year, 12, 25): _('Christmas Day'),
        date(year, 12, 26): _('Boxing Day'),
        }  # What the hell, you don't celebrate B. Britten's birthday???
Exemple #16
0
def get_german_holidays(year, place=[None, None, None], scope="legal", _=str):
    """
    Returns German holiday dates. Use the s for the german
    federal states like 'Germany/BY ' for Bayern.
    :
    Example: get_holidays(2015, place=['Germany', 'BE', 'Berlin'])
    """
    logging.debug("Feiertage für: {0}".format(place))
    if place[0] not in ["Deutschland", "deutschland", "Germany", "germany"]:
        logging.error("You are outside of Germany. The holidays will be incorrect.")
    # Determine Easter
    eastr = easter.easter(year)

    # Add national holidays
    adict = {
        date(year, 1, 1): "Neujahr",
        date(year, 5, 1): "Tag der Arbeit",
        date(year, 10, 3): "Tag der Deutschen Einheit",
        date(year, 12, 25): "1. Weihnachtstag",
        date(year, 12, 26): "2. Weihnachtstag",
        eastr - timedelta(days=2): "Karfreitag",
        eastr: "Ostersonntag",
        eastr + timedelta(days=1): "Ostermontag",
        eastr + timedelta(days=39): "Christi Himmelfahrt",
        eastr + timedelta(days=50): "Pfingstmontag",
    }

    # Add federal holidays
    if place[1].upper() in ("BW", "BY", "ST"):
        adict[date(year, 1, 6)] = "Heilige Drei Könige"

    if place[1] in ("BW", "BY", "HE", "NW", "RP", "SL"):
        adict[eastr + timedelta(days=60)] = "Frohnleichnam"

    if place[1].upper() in ("BY", "SL"):
        adict[date(year, 8, 15)] = "Mariä Himmelfahrt"

    if place[1].upper() in ("BB", "MV", "SN", "ST", "TH"):
        adict[date(year, 10, 31)] = "Reformationstag"

    if place[1].upper() in ("BW", "BY"):
        adict[date(year, 11, 1)] = "Allerheiligen"

    return adict
Exemple #17
0
def get_holidays(year):
    new_year = f"{year}-01-01"
    womens_day = f"{year}-03-08"
    easter_sun = easter(year)
    easter_mon = easter_sun + datetime.timedelta(days=1)
    easter_fri = easter_sun - datetime.timedelta(days=2)
    may_first = f"{year}-05-01"
    fathers_day = easter_sun + datetime.timedelta(days=40)
    whitsun = easter_sun + datetime.timedelta(days=50)
    unification_day = f"{year}-10-03"
    christmas_1 = f"{year}-12-25"
    christmas_2 = f"{year}-12-26"
    new_years_eve = f"{year}-12-31"
    out = pd.to_datetime([
        new_year, womens_day, easter_fri, easter_sun, easter_mon, may_first,
        fathers_day, whitsun, unification_day, christmas_1, christmas_2,
        new_years_eve
    ])
    return out
Exemple #18
0
def can_eat_meat(date):
    easter_date = easter.easter(date.year)

    for offset in HARD_FEASTS_EASTER_OFFSETS:
        if easter_date + offset == date:
            return False, 'hard'

    if date.weekday() == FRIDAY:
        for offset in SOLEMNITIES_EASTER_OFFSETS:
            if easter_date + offset == date:
                return True, 'solemnity'

        for solemn_month, solemn_day in SOLEMNITIES_NOT_MOVING:
            if date.month == solemn_month and date.day == solemn_day:
                return True, 'solemnity'

        return False, 'friday'

    return True, 'normal'
Exemple #19
0
    def _populate(self, year):
        if year <= 1990:
            return

        if year > 1991:
            self[date(year, JAN, 1)] = "novo leto"

            # Between 2012 and 2017 2nd January was not public holiday,
            # or at least not work-free day
            if year < 2013 or year > 2016:
                self[date(year, JAN, 2)] = "novo leto"

            # Prešeren's day, slovenian cultural holiday
            self[date(year, FEB, 8)] = "Prešernov dan"

            # Easter monday is the only easter related work-free day
            easter_day = easter(year)
            self[easter_day + rd(days=1)] = "Velikonočni ponedeljek"

            # Day of uprising against occupation
            self[date(year, APR, 27)] = "dan upora proti okupatorju"

            # Labour day, two days of it!
            self[date(year, MAY, 1)] = "praznik dela"
            self[date(year, MAY, 2)] = "praznik dela"

            # Statehood day
            self[date(year, JUN, 25)] = "dan državnosti"

            # Assumption day
            self[date(year, AUG, 15)] = "Marijino vnebovzetje"

            # Reformation day
            self[date(year, OCT, 31)] = "dan reformacije"

            # Remembrance day
            self[date(year, NOV, 1)] = "dan spomina na mrtve"

            # Christmas
            self[date(year, DEC, 25)] = "Božič"

            # Day of independence and unity
            self[date(year, DEC, 26)] = "dan samostojnosti in enotnosti"
    def _populate(self, year):
        # New Year's Day
        self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]"

        self[date(year, MAY, 1)] = "Dia Mundial del Trabajador"

        self[date(year, JUN, 24)] = "Batalla de Carabobo"

        self[date(year, JUL, 5)] = "Dia de la Independencia"

        self[date(year, JUL, 24)] = "Natalicio de Simón Bolívar"

        self[date(year, OCT, 12)] = "Día de la Resistencia Indígena"

        self[date(year, DEC, 17)] = "Muerte del Libertador Simón Bolívar"

        # Christmas Day
        self[date(year, DEC, 24)] = "Nochebuena"

        self[date(year, DEC, 25)] = "Día de Navidad"

        self[date(year, DEC, 31)] = "Fiesta de Fin de Año"

        # Semana Santa y Carnaval
        if date(year, APR, 19) == (easter(year) - rd(days=2)):
            self[date(year, APR,
                      19)] = "Viernes Santo y Declaración de la Independencia"
            self[easter(year) - rd(days=3)] = "Jueves Santo"
        elif date(year, APR, 19) == (easter(year) - rd(days=3)):
            self[date(year, APR,
                      19)] = "Jueves Santo y Declaración de la Independencia"
            self[easter(year) - rd(days=2)] = "Viernes Santo"
        else:
            self[date(year, APR, 19)] = "Declaración de la Independencia"
            self[easter(year) - rd(days=2)] = "Viernes Santo"
            self[easter(year) - rd(days=3)] = "Jueves Santo"

        self[easter(year) - rd(days=47)] = "Martes de Carnaval"

        self[easter(year) - rd(days=48)] = "Lunes de Carnaval"
Exemple #21
0
    def setup_this_year(self):
        """ Create this year date (not used for now)
        """
        period_pool = self.env['auto.confirm.period']
        year = fields.Datetime.now()[:4]

        date_excluded = {
            ('01-01', ): 'Capodanno',
            ('01-06', ): 'Befana',
            ('04-25', ): '25 Aprile',
            ('05-01', ): 'I Maggio',
            ('06-02', ): 'Festa della Repubblica',
            ('08-15', ): 'Ferragosto',
            ('12-08', ): 'Immacolata concezione',
            ('12-25', '12-26'): 'Natale',
        }
        easter_date = easter(int(year))
        easter_record = '%02d-%02d' % (easter_date.month, easter_date.day)
        date_excluded[easter_record] = 'Pasqua'

        if self.patron_day:
            patron_day = self.patron_day
            date_excluded[patron_day] = 'Festa patronale'

        for date in sorted(date_excluded, key=lambda r: r[0]):
            if len(date) == 2:
                from_date, to_date = date
            else:
                from_date = to_date = date
            name = date_excluded[date]
            periods = period_pool.search([('from_date', '=', from_date)])
            data = {
                'name': name,
                'company_id': self.env.user.company_id.id,
                'from_date': '{}-{}'.format(year, from_date),
                'to_date': '{}-{}'.format(year, to_date),
            }
            if periods:
                period_pool.write(data)
            else:
                period_pool.create(data)
        return True
    def _populate(self, year):
        # New years
        self[date(year, JAN, 1)] = "Nova Godina"
        # Epiphany
        self[date(year, JAN, 6)] = "Sveta tri kralja"
        easter_date = easter(year)

        # Easter
        self[easter_date] = "Uskrs"
        # Easter Monday
        self[easter_date + rd(days=1)] = "Uskrsni ponedjeljak"

        # Corpus Christi
        self[easter_date + rd(days=60)] = "Tijelovo"

        # International Workers' Day
        self[date(year, MAY, 1)] = "Međunarodni praznik rada"

        # Anti-fascist struggle day
        self[date(year, JUN, 22)] = "Dan antifašističke borbe"

        # Statehood day
        self[date(year, JUN, 25)] = "Dan državnosti"

        # Victory and Homeland Thanksgiving Day
        self[date(year, AUG, 5)] = "Dan pobjede i domovinske zahvalnosti"

        # Assumption of Mary
        self[date(year, AUG, 15)] = "Velika Gospa"

        # Independence Day
        self[date(year, OCT, 8)] = "Dan neovisnosti"

        # All Saints' Day
        self[date(year, NOV, 1)] = "Svi sveti"

        # Christmas day
        self[date(year, DEC, 25)] = "Božić"

        # St. Stephen's day
        self[date(year, DEC, 26)] = "Sveti Stjepan"
Exemple #23
0
    def _populate(self, year):
        # The current set of holidays came into force in 1998
        # http://laws.newsby.org/documents/ukazp/pos05/ukaz05806.htm
        if year <= 1998:
            return

        # New Year's Day
        self[date(year, JAN, 1)] = "Новый год"

        # Jan 2nd is the national holiday (New Year) from 2020
        # http://president.gov.by/uploads/documents/2019/464uk.pdf
        if year >= 2020:
            # New Year's Day
            self[date(year, JAN, 2)] = "Новый год"

        # Christmas Day (Orthodox)
        self[date(year, JAN, 7)] = ("Рождество Христово "
                                    "(православное Рождество)")

        # Women's Day
        self[date(year, MAR, 8)] = "День женщин"

        # Radunitsa ("Day of Rejoicing")
        self[easter(year, method=EASTER_ORTHODOX) + rd(days=9)] = "Радуница"

        # Labour Day
        self[date(year, MAY, 1)] = "Праздник труда"

        # Victory Day
        self[date(year, MAY, 9)] = "День Победы"

        # Independence Day
        self[date(year, JUL, 3)] = ("День Независимости Республики Беларусь "
                                    "(День Республики)")

        # October Revolution Day
        self[date(year, NOV, 7)] = "День Октябрьской революции"

        # Christmas Day (Catholic)
        self[date(year, DEC, 25)] = ("Рождество Христово "
                                     "(католическое Рождество)")
Exemple #24
0
def from_easter(year, shifts, easter_type='western', label=0):
    """Calculate holiday dates anchored to Easter.

    This function is to be used to build a (part of) `amendments` dictionary 
    for a day-based calendar.

    Parameters
    ----------
    year : int
    shifts : iterable of int
        List of holidays whose dates are to be found. The holidays are
        denominated in their distance from Easter. For example,
        -2 is Good Friday, 1 is Monday after Easter, 0 is Easter itself.
    easter_type: {'western', 'orthodox'}, optional (default 'western')
    label : optional (default 0)

    Returns
    -------
    dict 
        Dictionary suitable for `amendments` parameter of Timeboard with 
        `base_unit_freq='D'`. The keys are timestamps. The values of the 
        dictionary are set to the value of `label`.
        
    Example
    -------
    Create amendments for Good Friday and Easter Monday in 2017:
    
    >>> from_easter(2017, [-2, 1])
    {Timestamp('2017-04-14 00:00:00'): 0, Timestamp('2017-04-17 00:00:00'): 0}
    """
    assert easter_type in ['western', 'orthodox']
    if easter_type == 'western':
        _easter_type = 3
    elif easter_type == 'orthodox':
        _easter_type = 2
    easter_date = easter(year, _easter_type)
    amendments = {
        get_timestamp(easter_date + datetime.timedelta(days=shift)): label
        for shift in shifts
    }
    return amendments
Exemple #25
0
    def _populate(self, year):
        e = easter(year)

        self[date(year, JAN, 1)] = "Uudenvuodenpäivä"
        self[date(year, JAN, 6)] = "Loppiainen"
        self[e - rd(days=2)] = "Pitkäperjantai"
        self[e] = "Pääsiäispäivä"
        self[e + rd(days=1)] = "2. pääsiäispäivä"
        self[date(year, MAY, 1)] = "Vappu"
        self[e + rd(days=39)] = "Helatorstai"
        self[e + rd(days=49)] = "Helluntaipäivä"
        self[date(year, JUN, 20) + rd(weekday=SA)] = "Juhannuspäivä"
        self[date(year, OCT, 31) + rd(weekday=SA)] = "Pyhäinpäivä"
        self[date(year, DEC, 6)] = "Itsenäisyyspäivä"
        self[date(year, DEC, 25)] = "Joulupäivä"
        self[date(year, DEC, 26)] = "Tapaninpäivä"

        # Juhannusaatto (Midsummer Eve) and Jouluaatto (Christmas Eve) are not
        # official holidays, but are de facto.
        self[date(year, JUN, 19) + rd(weekday=FR)] = "Juhannusaatto"
        self[date(year, DEC, 24)] = "Jouluaatto"
Exemple #26
0
def generate_holydays(year):
    # Holydays with the same date every year
    holydays = {
        date(year, 1, 1): "Nyttårsdag",
        date(year, 5, 1): "Arbeidernes dag",
        date(year, 5, 17): "Grunnlovsdagen",
        date(year, 12, 25): "1. Juledag",
        date(year, 12, 26): "2. Juledag"
    }

    # Easter related stuff
    easter_sunday = easter(year)
    holydays[easter_sunday] = "1. Påskedag"
    holydays[easter_sunday + timedelta(days=1)] = "2. Påskedag"
    holydays[easter_sunday - timedelta(days=7)] = "Palmesøndag"
    holydays[easter_sunday - timedelta(days=3)] = "Skjærtorsdag"
    holydays[easter_sunday - timedelta(days=2)] = "Langfredag"
    holydays[easter_sunday + timedelta(days=39)] = "Kristi himmelfart"
    holydays[easter_sunday + timedelta(days=49)] = "1. Pinsedag"
    holydays[easter_sunday + timedelta(days=50)] = "2. Pinsedag"

    return holydays
 def _populate(self, year):
     # Public holidays
     self[date(year, JAN, 1)] = "Nýársdagur"
     self[easter(year) - rd(days=3)] = "Skírdagur"
     self[easter(year) + rd(weekday=FR(-1))] = "Föstudagurinn langi"
     self[easter(year)] = "Páskadagur"
     self[easter(year) + rd(days=1)] = "Annar í páskum"
     self[date(year, APR, 19) + rd(weekday=TH(+1))] = "Sumardagurinn fyrsti"
     self[date(year, MAY, 1)] = "Verkalýðsdagurinn"
     self[easter(year) + rd(days=39)] = "Uppstigningardagur"
     self[easter(year) + rd(days=49)] = "Hvítasunnudagur"
     self[easter(year) + rd(days=50)] = "Annar í hvítasunnu"
     self[date(year, JUN, 17)] = "Þjóðhátíðardagurinn"
     # First Monday of August
     self[date(year, AUG, 1) +
          rd(weekday=MO(+1))] = "Frídagur verslunarmanna"
     self[date(year, DEC, 24)] = "Aðfangadagur"
     self[date(year, DEC, 25)] = "Jóladagur"
     self[date(year, DEC, 26)] = "Annar í jólum"
     self[date(year, DEC, 31)] = "Gamlársdagur"
Exemple #28
0
    def _populate(self, year):

        eday = easter(year, method=EASTER_ORTHODOX)

        # New Years
        self[date(year, JAN, 1)] = "Πρωτοχρονιά [New Year's Day]"
        # Epiphany
        self[date(year, JAN, 6)] = "Θεοφάνεια [Epiphany]"

        # Clean Monday
        self[eday - rd(days=48)] = "Καθαρά Δευτέρα [Clean Monday]"

        # Independence Day
        self[date(year, MAR, 25)] = "Εικοστή Πέμπτη Μαρτίου [Independence Day]"

        # Easter Monday
        self[eday + rd(days=1)] = "Δευτέρα του Πάσχα [Easter Monday]"

        # Labour Day
        self[date(year, MAY, 1)] = "Εργατική Πρωτομαγιά [Labour day]"

        # Monday of the Holy Spirit
        self[eday +
             rd(days=50
                )] = "Δευτέρα του Αγίου Πνεύματος [Monday of the Holy Spirit]"

        # Assumption of Mary
        self[date(year, AUG, 15)] = "Κοίμηση της Θεοτόκου [Assumption of Mary]"

        # Ochi Day
        self[date(year, OCT, 28)] = "Ημέρα του Όχι [Ochi Day]"

        # Christmas
        self[date(year, DEC, 25)] = "Χριστούγεννα [Christmas]"

        # Day after Christmas
        self[date(
            year, DEC,
            26)] = "Επόμενη ημέρα των Χριστουγέννων [Day after Christmas]"
    def _populate(self, year):
        # New years
        self[date(year, JAN, 1)] = "Nieuwjaarsdag"

        easter_date = easter(year)

        # Easter
        self[easter_date] = "Pasen"

        # Second easter day
        self[easter_date + rd(days=1)] = "Paasmaandag"

        # Ascension day
        self[easter_date + rd(days=39)] = "O.L.H. Hemelvaart"

        # Pentecost
        self[easter_date + rd(days=49)] = "Pinksteren"

        # Pentecost monday
        self[easter_date + rd(days=50)] = "Pinkstermaandag"

        # International Workers' Day
        self[date(year, MAY, 1)] = "Dag van de Arbeid"

        # Belgian National Day
        self[date(year, JUL, 21)] = "Nationale feestdag"

        # Assumption of Mary
        self[date(year, AUG, 15)] = "O.L.V. Hemelvaart"

        # All Saints' Day
        self[date(year, NOV, 1)] = "Allerheiligen"

        # Armistice Day
        self[date(year, NOV, 11)] = "Wapenstilstand"

        # First christmas
        self[date(year, DEC, 25)] = "Kerstmis"
    def _populate(self, year):

        eday = easter(year, method=EASTER_ORTHODOX)

        # New Year
        for day in [1, 2]:
            self[date(year, JAN, day)] = "Anul Nou"

        # Anniversary of the formation of the United Principalities
        self[date(year, JAN, 24)] = "Unirea Principatelor Române"

        # Easter (Friday, Sunday and Monday)
        for day_after_easter in [-2, 0, 1]:
            self[eday + rd(days=day_after_easter)] = "Paștele"

        # Labour Day
        self[date(year, MAY, 1)] = "Ziua Muncii"

        # Children's Day (since 2017)
        if year >= 2017:
            self[date(year, JUN, 1)] = "Ziua Copilului"

        # Whit Monday
        for day_after_easter in [49, 50]:
            self[eday + rd(days=day_after_easter)] = "Rusaliile"

        # Assumption of Mary
        self[date(year, AUG, 15)] = "Adormirea Maicii Domnului"

        # St. Andrew's Day
        self[date(year, NOV, 30)] = "Sfântul Andrei"

        # National Day
        self[date(year, DEC, 1)] = "Ziua Națională a României"

        # Christmas Day
        self[date(year, DEC, 25)] = "Crăciunul"
        self[date(year, DEC, 26)] = "Crăciunul"
    def _populate(self, year):
        e = easter(year)

        # New Year's Day
        self[date(year, JAN, 1)] = "uusaasta"

        # Independence Day, anniversary of the Republic of Estonia
        self[date(year, FEB, 24)] = "iseseisvuspäev"

        # Good Friday
        self[e - rd(days=2)] = "suur reede"

        # Easter Sunday
        self[e] = "ülestõusmispühade 1. püha"

        # Spring Day
        self[date(year, MAY, 1)] = "kevadpüha"

        # Pentecost
        self[e + rd(days=49)] = "nelipühade 1. püha"

        # Victory Day
        self[date(year, JUN, 23)] = "võidupüha"

        # Midsummer Day
        self[date(year, JUN, 24)] = "jaanipäev"

        # Day of Restoration of Independence
        self[date(year, AUG, 20)] = "taasiseseisvumispäev"

        # Christmas Eve
        self[date(year, DEC, 24)] = "jõululaupäev"

        # Christmas Day
        self[date(year, DEC, 25)] = "esimene jõulupüha"

        # Boxing Day
        self[date(year, DEC, 26)] = "teine jõulupüha"
Exemple #32
0
def get_holidays(year, place=['Poland', None, None], scope='legal', _=str):
    """Returns Polish holiday dates (legally considered non-working days)."""
    easter_sunday = easter.easter(year)
    return {
        date(year, 1, 1): _('New Year'),
        date(year, 1, 6): _('Trzech Kroli'),
        easter_sunday: _('Easter Sunday'),
        easter_sunday + timedelta(days=1): _('Easter Monday'),
        date(year, 5, 1): _('Labor Day'),
        date(year, 5, 3): _('Constitution Day'),
        # 7th Sunday after Easter
        # (notice days+1 - this is 7th Sunday excluding Easter Sunday
        easter_sunday + relativedelta(days=+1, weekday=SU(+7)):
        _('Pentecost Sunday'),
        # 9th Thursday after Easter
        easter_sunday + relativedelta(weekday=TH(+9)):
        _('Corpus Christi'),
        date(year, 8, 15): _('Assumption of the Blessed Virgin Mary'),
        date(year, 11, 1): _("All Saints' Day"),
        date(year, 11, 11): _('Independence Day'),
        date(year, 12, 25): _('Christmas Day'),
        date(year, 12, 26): _('Boxing Day'),
        }  # What the hell, you don't celebrate Chopin's birthday???
Exemple #33
0
def get_holidays(year=2010):
    """ Returns Polish hollidays dates (legally considered non-working days) """
    easter_sunday = easter.easter(year)
    holidays = {
        'New Year': date(year, 1, 1),
        'Trzech Kroli': date(year, 1, 6),
        'Easter Sunday': easter_sunday,
        'Easter Monday': easter_sunday + timedelta(days=1),
        'Labor Day': date(year, 5, 1),
        'Constitution Day': date(year, 5, 3),
        # 7th Sunday after Easter
        # (notice days+1 - this is 7th Sunday excluding Easter Sunday
        'Pentecost Sunday':
        easter_sunday + relativedelta(days=+1, weekday=SU(+7)),
        # 9th Thursday after Easter
        'Corpus Christi': easter_sunday + relativedelta(weekday=TH(+9)),
        'Assumption of the Blessed Virgin Mary': date(year, 8, 15),
        'All Saints\' Day': date(year, 11, 1),
        'Independence Day': date(year, 11, 11),
        'Christmas  Day': date(year, 12, 25),
        'Boxing Day': date(year, 12, 26),
    }
    return holidays
Exemple #34
0
    def _populate(self, year):
        # New Year's Day
        name = "New Year's Day"
        self[date(year, 1, 1)] = name

        # Orthodox Christmas day
        name = "Orthodox Christmas Day"
        self[date(year, 1, 7)] = name

        # International Women's Day
        name = "International Women's Day"
        self[date(year, 3, 8)] = name

        # Commemoration Day
        name = "Commemoration Day"
        self[easter(year, EASTER_ORTHODOX) + timedelta(days=9)] = name

        # Spring and Labour Day
        name = "Spring and Labour Day"
        self[date(year, 5, 1)] = name

        # Victory Day
        name = "Victory Day"
        self[date(year, 5, 9)] = name

        # Independence Day
        name = "Independence Day"
        self[date(year, 7, 3)] = name

        # October Revolution Day
        name = "October Revolution Day"
        self[date(year, 11, 7)] = name

        # Dec. 25 Christmas Day
        name = "Christmas Day"
        self[date(year, 12, 25)] = name
    def _populate(self, year):
        self[date(year, JAN, 1)] = "Ano Novo"

        e = easter(year)

        # carnival is no longer a holiday, but some companies let workers off.
        # @todo recollect the years in which it was a public holiday
        # self[e - rd(days=47)] = "Carnaval"
        self[e - rd(days=2)] = "Sexta-feira Santa"
        self[e] = "Páscoa"

        # Revoked holidays in 2013–2015
        if year < 2013 or year > 2015:
            self[e + rd(days=60)] = "Corpo de Deus"
            self[date(year, OCT, 5)] = "Implantação da República"
            self[date(year, NOV, 1)] = "Dia de Todos os Santos"
            self[date(year, DEC, 1)] = "Restauração da Independência"

        self[date(year, 4, 25)] = "Dia da Liberdade"
        self[date(year, 5, 1)] = "Dia do Trabalhador"
        self[date(year, 6, 10)] = "Dia de Portugal"
        self[date(year, 8, 15)] = "Assunção de Nossa Senhora"
        self[date(year, DEC, 8)] = "Imaculada Conceição"
        self[date(year, DEC, 25)] = "Dia de Natal"
Exemple #36
0
    def _populate(self, year):
        if year > 1995:
            # https://www.ilo.org/dyn/travail/docs/2093/Public%20Holidays%20Act%201995.pdf
            self[date(year, JAN, 1)] = "New Year's Day"
            self[date(year, MAR, 11)] = "Moshoeshoe's Day"

            if year == 2002:
                # https://tinyurl.com/lesothourl
                self[date(year, APR, 4)] = "Heroes Day"
                self[date(year, MAY, 25)] = "Africa Day"

            if year < 2002:
                self[date(year, APR, 4)] = "Heroes Day"

            if year > 2002:
                self[date(year, MAY, 25)] = "Africa/Heroes Day"

            e = easter(year)
            good_friday = e - rd(days=2)
            easter_monday = e + rd(days=1)
            ascension_day = e + rd(days=39)

            self[good_friday] = "Good Friday"
            self[easter_monday] = "Easter Monday"
            self[ascension_day] = "Ascension Day"
            self[date(year, MAY, 1)] = "Workers' Day"

            if year > 1997:
                # https://en.wikipedia.org/wiki/Letsie_III
                self[date(year, JUL, 17)] = "King's Birthday"
            if year <= 1997:
                self[date(year, MAY, 2)] = "King's Birthday"

            self[date(year, OCT, 4)] = "National Independence Day"
            self[date(year, DEC, 25)] = "Christmas Day"
            self[date(year, DEC, 26)] = "Boxing Day"
    def _populate(self, year):
        self[date(year, JAN, 1)] = "Deň vzniku Slovenskej republiky"
        self[date(year, JAN, 6)] = "Zjavenie Pána (Traja králi a" \
                                   " vianočnýsviatok pravoslávnych" \
                                   " kresťanov)"

        e = easter(year)
        self[e - rd(days=2)] = "Veľký piatok"
        self[e + rd(days=1)] = "Veľkonočný pondelok"

        self[date(year, MAY, 1)] = "Sviatok práce"

        if year >= 1997:
            self[date(year, MAY, 8)] = "Deň víťazstva nad fašizmom"

        self[date(year, JUL, 5)] = "Sviatok svätého Cyrila a svätého Metoda"

        self[date(year, AUG, 29)] = "Výročie Slovenského národného" \
                                    " povstania"

        self[date(year, SEP, 1)] = "Deň Ústavy Slovenskej republiky"

        self[date(year, SEP, 15)] = "Sedembolestná Panna Mária"
        if year == 2018:
            self[date(year, OCT, 30)] = "100. výročie prijatia" \
                " Deklarácie slovenského národa"
        self[date(year, NOV, 1)] = "Sviatok Všetkých svätých"

        if year >= 2001:
            self[date(year, NOV, 17)] = "Deň boja za slobodu a demokraciu"

        self[date(year, DEC, 24)] = "Štedrý deň"

        self[date(year, DEC, 25)] = "Prvý sviatok vianočný"

        self[date(year, DEC, 26)] = "Druhý sviatok vianočný"
Exemple #38
0
 def get_easter_sunday(self, year):
     "Return the date of the easter (sunday) -- following the easter method"
     return easter.easter(year, self.EASTER_METHOD)
    def _populate(self, year):
        # Civil holidays
        if year > 1810:
            self[date(year, JAN, 1)] = "Jour de l'an"

        if year > 1919:
            name = 'Fête du Travail'
            if year <= 1948:
                name += ' et de la Concorde sociale'
            self[date(year, MAY, 1)] = name

        if (1953 <= year <= 1959) or year > 1981:
            self[date(year, MAY, 8)] = 'Armistice 1945'

        if year >= 1880:
            self[date(year, JUL, 14)] = 'Fête nationale'

        if year >= 1918:
            self[date(year, NOV, 11)] = 'Armistice 1918'

        # Religious holidays
        if self.prov in [
                'Alsace-Moselle', 'Guadeloupe', 'Guyane', 'Martinique',
                'Polynésie Française'
        ]:
            self[easter(year) - rd(days=2)] = 'Vendredi saint'

        if self.prov == 'Alsace-Moselle':
            self[date(year, DEC, 26)] = 'Deuxième jour de Noël'

        if year >= 1886:
            self[easter(year) + rd(days=1)] = 'Lundi de Pâques'
            self[easter(year) + rd(days=50)] = 'Lundi de Pentecôte'

        if year >= 1802:
            self[easter(year) + rd(days=39)] = 'Ascension'
            self[date(year, AUG, 15)] = 'Assomption'
            self[date(year, NOV, 1)] = 'Toussaint'

            name = 'Noël'
            if self.prov == 'Alsace-Moselle':
                name = 'Premier jour de ' + name
            self[date(year, DEC, 25)] = name

        # Non-metropolitan holidays (starting dates missing)
        if self.prov == 'Mayotte':
            self[date(year, APR, 27)] = "Abolition de l'esclavage"

        if self.prov == 'Wallis-et-Futuna':
            self[date(year, APR, 28)] = 'Saint Pierre Chanel'

        if self.prov == 'Martinique':
            self[date(year, MAY, 22)] = "Abolition de l'esclavage"

        if self.prov in ['Guadeloupe', 'Saint-Martin']:
            self[date(year, MAY, 27)] = "Abolition de l'esclavage"

        if self.prov == 'Guyane':
            self[date(year, JUN, 10)] = "Abolition de l'esclavage"

        if self.prov == 'Polynésie Française':
            self[date(year, JUN, 29)] = "Fête de l'autonomie"

        if self.prov in ['Guadeloupe', 'Martinique']:
            self[date(year, JUL, 21)] = 'Fête Victor Schoelcher'

        if self.prov == 'Wallis-et-Futuna':
            self[date(year, JUL, 29)] = 'Fête du Territoire'

        if self.prov == 'Nouvelle-Calédonie':
            self[date(year, SEP, 24)] = 'Fête de la Citoyenneté'

        if self.prov == 'Saint-Barthélémy':
            self[date(year, OCT, 9)] = "Abolition de l'esclavage"

        if self.prov == 'La Réunion' and year >= 1981:
            self[date(year, DEC, 20)] = "Abolition de l'esclavage"
    def OnBoutonOk(self, event): 
        # Récupération des années
        annee_depart = self.ctrl_annee.GetValue()
        nbre_annees = self.ctrl_nbre.GetValue()

        # Génération de la liste des années :
        listeAnnees = range(annee_depart, annee_depart+nbre_annees)

        # Récupération jours fériés à créer
        listeCoches = []
        for index in range(0, self.ctrl_jours.GetCount()):
            if self.ctrl_jours.IsChecked(index):
                listeCoches.append(index)

        if len(listeCoches) == 0 :
            dlg = wx.MessageDialog(self, _(u"Vous devez obligatoirement cocher au moins un jour férié à créer !"), _(u"Erreur"), wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal()
            dlg.Destroy()
            return False
        
        # Récupération des jours déjà présents dans la base de données
        DB = GestionDB.DB() 
        req = """SELECT IDferie, nom, jour, mois, annee
        FROM jours_feries
        WHERE type='variable' ; """
        DB.ExecuterReq(req)
        listeDonnees = DB.ResultatReq()
        listeJoursExistants = []
        for IDferie, nom, jour, mois, annee in listeDonnees :
            try :
                listeJoursExistants.append(datetime.date(annee, mois, jour))
            except :
                pass
        
        def SauvegarderDate(nom="", date=None):
            if date not in listeJoursExistants :
                IDferie = DB.ReqInsert("jours_feries", [("type", "variable"), ("nom", nom), ("annee", date.year), ("mois", date.month), ("jour", date.day)])


        # Calcul des jours fériés
        for annee in listeAnnees :
            
            # Dimanche de Paques
            dimanche_paques = easter(annee)
            
            # Lundi de Pâques
            lundi_paques = dimanche_paques + relativedelta(days=+1)
            if 0 in listeCoches : SauvegarderDate(_(u"Lundi de Pâques"), lundi_paques)
            
            # Ascension
            ascension = dimanche_paques + relativedelta(days=+39)
            if 1 in listeCoches : SauvegarderDate(_(u"Jeudi de l'Ascension"), ascension)

            # Pentecote
            pentecote = dimanche_paques + relativedelta(days=+50)
            if 2 in listeCoches : SauvegarderDate(_(u"Lundi de Pentecôte"), pentecote)
        
        DB.Close()
        
        # Fermeture
        self.EndModal(wx.ID_OK)
Exemple #41
0
    def _populate(self, year):
        def storeholiday(self, hol_date, hol_name):
            """
            Function to store the holiday name in the appropriate
            date and to implement Section 4(2) of the Holidays Act:
            'if any day specified in the Schedule falls on a Sunday,
            the day next following not being itself a public holiday
            is declared a public holiday in Singapore.'
            """
            if hol_date.weekday() == SUN:
                self[hol_date] = hol_name + " [Sunday]"
                self[hol_date + rd(days=+1)] = "Monday following " + hol_name
            else:
                self[hol_date] = hol_name

        # New Year's Day
        storeholiday(self, date(year, JAN, 1), "New Year's Day")

        # Chinese New Year (two days)
        hol_date = self.get_lunar_n_y_date(year)
        self[hol_date] = "Chinese New Year"
        storeholiday(self, hol_date + rd(days=+1), "Chinese New Year")

        # Hari Raya Puasa
        # aka Eid al-Fitr
        # date of observance is announced yearly
        dates_obs = {
            2001: [(DEC, 16)],
            2002: [(DEC, 6)],
            2003: [(NOV, 25)],
            2004: [(NOV, 14)],
            2005: [(NOV, 3)],
            2006: [(OCT, 24)],
            2007: [(OCT, 13)],
            2008: [(OCT, 1)],
            2009: [(SEP, 20)],
            2010: [(SEP, 10)],
            2011: [(AUG, 30)],
            2012: [(AUG, 19)],
            2013: [(AUG, 8)],
            2014: [(JUL, 28)],
            2015: [(JUL, 17)],
            2016: [(JUL, 6)],
            2017: [(JUN, 25)],
            2018: [(JUN, 15)],
            2019: [(JUN, 5)],
            2020: [(MAY, 24)]
        }
        if year in dates_obs:
            for date_obs in dates_obs[year]:
                hol_date = date(year, *date_obs)
                storeholiday(self, hol_date, "Hari Raya Puasa")
                # Second day of Hari Raya Puasa (up to and including 1968)
                # Removed since we don't have Hari Raya Puasa dates for the
                # the years <= 1968:
                # if year <= 1968:
                #     storeholiday(self, hol_date + rd(days=+1),
                #                  "Second day of Hari Raya Puasa")
        else:
            for date_obs in self.get_hrp_date(year):
                hol_date = date_obs
                storeholiday(self, hol_date, "Hari Raya Puasa* (*estimated)")
                # Second day of Hari Raya Puasa (up to and including 1968)
                if year <= 1968:
                    storeholiday(
                        self, hol_date + rd(days=+1),
                        "Second day of Hari Raya Puasa* (*estimated)")

        # Hari Raya Haji
        # aka Eid al-Adha
        # date of observance is announced yearly
        dates_obs = {
            2001: [(MAR, 6)],
            2002: [(FEB, 23)],
            2003: [(FEB, 12)],
            2004: [(FEB, 1)],
            2005: [(JAN, 21)],
            2006: [(JAN, 10)],
            2007: [(DEC, 20)],
            2008: [(DEC, 8)],
            2009: [(NOV, 27)],
            2010: [(NOV, 17)],
            2011: [(NOV, 6)],
            2012: [(OCT, 26)],
            2013: [(OCT, 15)],
            2014: [(OCT, 5)],
            2015: [(SEP, 24)],
            2016: [(SEP, 12)],
            2017: [(SEP, 1)],
            2018: [(AUG, 22)],
            2019: [(AUG, 11)],
            2020: [(JUL, 31)]
        }
        if year in dates_obs:
            for date_obs in dates_obs[year]:
                hol_date = date(year, *date_obs)
                storeholiday(self, hol_date, "Hari Raya Haji")
        else:
            for date_obs in self.get_hrh_date(year):
                hol_date = date_obs
                storeholiday(self, hol_date, "Hari Raya Haji* (*estimated)")

        # Holy Saturday (up to and including 1968)
        if year <= 1968:
            self[easter(year) + rd(weekday=SA(-1))] = "Holy Saturday"

        # Good Friday
        self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"

        # Easter Monday
        if year <= 1968:
            self[easter(year) + rd(weekday=MO(1))] = "Easter Monday"

        # Labour Day
        storeholiday(self, date(year, MAY, 1), "Labour Day")

        # Vesak Day
        # date of observance is announced yearly
        # https://en.wikipedia.org/wiki/Vesak#Dates_of_observance
        dates_obs = {
            2001: (MAY, 7),
            2002: (MAY, 27),
            2003: (MAY, 15),
            2004: (JUN, 2),
            2005: (MAY, 23),
            2006: (MAY, 12),
            2007: (MAY, 31),
            2008: (MAY, 19),
            2009: (MAY, 9),
            2010: (MAY, 28),
            2011: (MAY, 17),
            2012: (MAY, 5),
            2013: (MAY, 24),
            2014: (MAY, 13),
            2015: (JUN, 1),
            2016: (MAY, 20),
            2017: (MAY, 10),
            2018: (MAY, 29),
            2019: (MAY, 19),
            2020: (MAY, 7)
        }
        if year in dates_obs:
            hol_date = date(year, *dates_obs[year])
            storeholiday(self, hol_date, "Vesak Day")
        else:
            storeholiday(self, self.get_vesak_date(year),
                         "Vesak Day* (*estimated; ~10% chance +/- 1 day)")

        # National Day
        storeholiday(self, date(year, AUG, 9), "National Day")

        # Deepavali
        # aka Diwali
        # date of observance is announced yearly
        dates_obs = {
            2001: (NOV, 14),
            2002: (NOV, 3),
            2003: (OCT, 23),
            2004: (NOV, 11),
            2005: (NOV, 1),
            2006: (OCT, 21),
            2007: (NOV, 8),
            2008: (OCT, 27),
            2009: (OCT, 17),
            2010: (NOV, 5),
            2011: (OCT, 26),
            2012: (NOV, 13),
            2013: (NOV, 2),
            2014: (OCT, 22),
            2015: (NOV, 10),
            2016: (OCT, 29),
            2017: (OCT, 18),
            2018: (NOV, 6),
            2019: (OCT, 27),
            2020: (NOV, 14)
        }
        if year in dates_obs:
            hol_date = date(year, *dates_obs[year])
            storeholiday(self, hol_date, "Deepavali")
        else:
            storeholiday(self, self.get_s_diwali_date(year),
                         "Deepavali* (*estimated; rarely on day after)")

        # Christmas Day
        storeholiday(self, date(year, DEC, 25), "Christmas Day")

        # Boxing day (up to and including 1968)
        if year <= 1968:
            storeholiday(self, date(year, DEC, 26), "Boxing Day")

        # Polling Day
        dates_obs = {
            2001: (NOV, 3),
            2006: (MAY, 6),
            2011: (MAY, 7),
            2015: (SEP, 11)
        }
        if year in dates_obs:
            self[date(year, *dates_obs[year])] = "Polling Day"

        # SG50 Public holiday
        # Announced on 14 March 2015
        # https://www.mom.gov.sg/newsroom/press-releases/2015/sg50-public-holiday-on-7-august-2015
        if year == 2015:
            self[date(2015, AUG, 7)] = "SG50 Public Holiday"
Exemple #42
0
def objects():
    cal = rt.models.cal
    PlannerColumns = cal.PlannerColumns
    # add = Instantiator('cal.Priority', 'ref').build
    # yield add('1', **dd.babel_values('name', en=u"very urgent", de=u"sehr dringend",   fr=u"très urgent", et=u"väga kiire"))
    # yield add('3', **dd.babel_values('name', en=u"urgent", de=u"dringend",   fr=u"urgent", et="kiire"))
    # yield add('5', **dd.babel_values('name', en=u"normal", de=u"normal",   fr=u"normal", et="keskmine"))
    # yield add('9', **dd.babel_values('name', en=u"not urgent", de=u"nicht dringend",   fr=u"pas urgent", et="mitte kiire"))

    calendar = Instantiator('cal.Calendar').build
    general = calendar(**dd.str2kw('name', _("General")))
    yield general
    # settings.SITE.site_config.site_calendar = general
    d = dd.demo_date()
    if d.month > 4:
        d = d.replace(month=1, day=1)
    else:
        d = d.replace(month=1, day=1, year=d.year-1)
    settings.SITE.site_config.update(
        site_calendar=general, hide_events_before=d)

    # yield settings.SITE.site_config

    event_type = Instantiator('cal.EventType').build
    holidays = event_type(
        planner_column=PlannerColumns.external,
        is_appointment=False,
        all_rooms=True, **dd.str2kw('name', _("Holidays")))
    yield holidays
    meeting = event_type(
        planner_column=PlannerColumns.external,
        default_duration="1:00", **dd.str2kw('name', _("Meeting")))
    yield meeting
    yield event_type(
        planner_column=PlannerColumns.internal,
        transparent=True,
        default_duration="0:30",
        **dd.str2kw('name', _("Internal")))

    RecurrentEvent = rt.models.cal.RecurrentEvent
    add = Instantiator(RecurrentEvent, event_type=holidays).build

    def holiday(month, day, en, de, fr, et=None):
        if et is None:
            et = en
        return add(
            every_unit=Recurrencies.yearly,
            monday=True, tuesday=True, wednesday=True, thursday=True,
            friday=True, saturday=True, sunday=True,
            every=1,
            start_date=datetime.date(
                year=cal.DEMO_START_YEAR,
                month=month, day=day),
            **dd.babelkw('name', en=en, de=de, fr=fr, et=et))
    yield holiday(1, 1, "New Year's Day", "Neujahr", "Jour de l'an", "Uusaasta")
    yield holiday(5, 1, "International Workers' Day", "Tag der Arbeit", "Premier Mai", "kevadpüha")
    yield holiday(7, 21, "National Day", "Nationalfeiertag", "Fête nationale", "Belgia riigipüha")
    yield holiday(8, 15, "Assumption of Mary", "Mariä Himmelfahrt", "Assomption de Marie")
    yield holiday(10, 31, "All Souls' Day", "Allerseelen", "Commémoration des fidèles défunts")
    yield holiday(11, 1, "All Saints' Day", "Allerheiligen", "Toussaint")
    yield holiday(11, 11, "Armistice with Germany", "Waffenstillstand", "Armistice")
    yield holiday(12, 25, "Christmas", "Weihnachten", "Noël", "Esimene Jõulupüha")

    easter1 = easter(cal.DEMO_START_YEAR)

    def relative_holiday(offset, name):
        return add(
            every_unit=Recurrencies.easter, every=1,
            start_date=easter1+relativedelta(days=offset),
            **dd.str2kw('name', name))

    yield relative_holiday(0, _("Easter sunday"))
    yield relative_holiday(1, _("Easter monday"))
    yield relative_holiday(39, _("Ascension of Jesus"))
    yield relative_holiday(50, _("Pentecost"))
    yield relative_holiday(-2, _("Good Friday"))
    yield relative_holiday(-46, _("Ash Wednesday"))
    yield relative_holiday(-48, _("Rosenmontag"))

    ar = settings.SITE.login()
    for obj in RecurrentEvent.objects.all():
        if not obj.update_reminders(ar):
            raise Exception("Oops, %s generated no events" % obj)

    # event policies

    kw = dict()
    for wd in WORKDAYS:
        kw[wd.name] = True
    kw.update(event_type=meeting)
    exam_policy = Instantiator(
        'cal.EventPolicy', 'every',
        every_unit=DurationUnits.months, **kw).build
    yield exam_policy(
        1, start_time="9:00",
        **dd.str2kw('name', _("Every month")))
    yield exam_policy(
        2, start_time="9:00",
        **dd.str2kw('name', _("Every 2 months")))
    yield exam_policy(
        3, **dd.str2kw('name', _("Every 3 months")))

    exam_policy = Instantiator(
        'cal.EventPolicy', 'every',
        every_unit=DurationUnits.weeks, **kw).build
    yield exam_policy(
        2, start_time="9:00",
        **dd.str2kw('name', _("Every 2 weeks")))

    exam_policy = Instantiator(
        'cal.EventPolicy', 'every',
        every_unit=DurationUnits.days, **kw).build
    yield exam_policy(
        10, max_events=1, start_time="9:00",
        **dd.str2kw('name', _("Once after 10 days")))

    exam_policy = Instantiator('cal.EventPolicy').build
    yield exam_policy(**dd.str2kw('name', _("Other")))

    DPR = rt.models.cal.DailyPlannerRow
    yield DPR(end_time="12:00", **dd.str2kw('designation', _("AM")))
    yield DPR(start_time="12:00", **dd.str2kw('designation', _("PM")))
    yield DPR(**dd.str2kw('designation', _("All day")))
    def _populate(self, year):
        if self.country == "US":
            # New Year's Day
            if year > 1870:
                self[date(year, 1, 1)] = "New Year's Day"
                if self.observed and date(year,1,1).weekday() == 5:
                    self[date(year,1,1)+rd(days=-1)] = "New Year's Day (Observed)"
                elif self.observed and date(year,1,1).weekday() == 6:
                    self[date(year,1,1)+rd(days=+1)] = "New Year's Day (Observed)"

            # Martin Luther King, Jr. Day
            if year >= 1986:
                self[date(year, 1, 1)+rd(weekday=MO(+3))] = "Martin Luther King, Jr. Day"

            # Washington's Birthday
            if year > 1970:
                self[date(year, 2, 1)+rd(weekday=MO(+3))] = "Washington's Birthday"
            elif year >= 1879:
                self[date(year, 2,22)] = "Washington's Birthday"

            # Memorial Day
            if year > 1970:
                self[date(year, 5,31)+rd(weekday=MO(-1))] = "Memorial Day"
            elif year >= 1888:
                self[date(year, 5,30)] = "Memorial Day"

            # Independence Day
            if year > 1870:
                self[date(year, 7, 4)] = "Independence Day"
                if self.observed and date(year,7,4).weekday() == 5:
                    self[date(year,7,4)+rd(days=-1)] = "Independence Day (Observed)"
                elif self.observed and date(year,7,4).weekday() == 6:
                    self[date(year,7,4)+rd(days=+1)] = "Independence Day (Observed)"

            # Labor Day
            if year >= 1894:
                self[date(year, 9, 1)+rd(weekday=MO)] = "Labor Day"

            # Columbus Day
            if year >= 1970:
                self[date(year,10, 1)+rd(weekday=MO(+2))] = "Columbus Day"
            elif year >= 1937:
                self[date(year,10,12)] = "Columbus Day"

            # Veterans Day
            if year > 1953:
                name = "Veterans Day"
            else:
                name = "Armistice Day"
            if 1978 > year > 1970:
                self[date(year,10, 1)+rd(weekday=MO(+4))] = name
            elif year >= 1938:
                self[date(year,11,11)] = name
                if self.observed and  date(year,11,11).weekday() == 5:
                    self[date(year,11,11)+rd(days=-1)] = name + " (Observed)"
                elif self.observed and date(year,11,11).weekday() == 6:
                    self[date(year,11,11)+rd(days=+1)] = name + " (Observed)"

            # Thanksgiving
            if year > 1870:
                self[date(year,11, 1)+rd(weekday=TH(+4))] = "Thanksgiving"

            # Christmas Day
            if year > 1870:
                self[date(year,12,25)] = "Christmas Day"
                if self.observed and  date(year,12,25).weekday() == 5:
                    self[date(year,12,25)+rd(days=-1)] = "Christmas Day (Observed)"
                elif self.observed and date(year,12,25).weekday() == 6:
                    self[date(year,12,25)+rd(days=+1)] = "Christmas Day (Observed)"

        elif self.country == "CA":
            # New Year's Day
            if year >= 1867:
                self[date(year, 1, 1)] = "New Year's Day"
                if self.observed and date(year,1,1).weekday() == 5:
                    self[date(year,1,1)+rd(days=-1)] = "New Year's Day (Observed)"
                elif self.observed and date(year,1,1).weekday() == 6:
                    self[date(year,1,1)+rd(days=+1)] = "New Year's Day (Observed)"

            # Islander Day
            if self.prov == 'PE' and year >= 2010:
                self[date(year,2,1)+rd(weekday=MO(+3))] = "Islander Day"
            elif self.prov == 'PE' and year == 2009:
                self[date(year,2,1)+rd(weekday=MO(+2))] = "Islander Day"

            # Family Day / Louis Riel Day (MB)
            if self.prov in ('AB','SK','ON') and year >= 2008:
                self[date(year,2,1)+rd(weekday=MO(+3))] = "Family Day"
            elif self.prov in ('AB','SK') and year >= 2007:
                self[date(year,2,1)+rd(weekday=MO(+3))] = "Family Day"
            elif self.prov == 'AB' and year >= 1990:
                self[date(year,2,1)+rd(weekday=MO(+3))] = "Family Day"
            elif self.prov == 'BC' and year >= 2013:
                self[date(year,2,1)+rd(weekday=MO(+2))] = "Family Day"
            elif self.prov == 'MB' and year >= 2008:
                self[date(year,2,1)+rd(weekday=MO(+3))] = "Louis Riel Day"

            # St. Patrick's Day
            if self.prov == 'NL' and year >= 1900:
                dt = date(year,3,17)
                # Nearest Monday to March 17
                dt1 = date(year,3,17)+rd(weekday=MO(-1))
                dt2 = date(year,3,17)+rd(weekday=MO(+1))
                if dt2 - dt <= dt - dt1:
                    self[dt2] = "St. Patrick's Day"
                else:
                    self[dt1] = "St. Patrick's Day"

            # Good Friday
            if self.prov != 'QC' and year >= 1867:
                self[easter(year)+rd(weekday=FR(-1))] = "Good Friday"

            # Easter Monday
            if self.prov == 'QC' and year >= 1867:
                self[easter(year)+rd(weekday=MO)] = "Easter Monday"

            # St. George's Day
            if self.prov == 'NL' and year == 2010:
                # 4/26 is the Monday closer to 4/23 in 2010
                # but the holiday was observed on 4/19? Crazy Newfies!
                self[date(2010,4,19)] = "St. George's Day"
            elif self.prov == 'NL' and year >= 1990:
                dt = date(year,4,23)
                # Nearest Monday to April 23
                dt1 = dt+rd(weekday=MO(-1))
                dt2 = dt+rd(weekday=MO(+1))
                if dt2 - dt < dt - dt1:
                    self[dt2] = "St. George's Day"
                else:
                    self[dt1] = "St. George's Day"

            # Victoria Day / National Patriotes Day (QC)
            if self.prov not in ('NB', 'NS', 'PE', 'NL','QC') and year >= 1953:
                self[date(year,5,24)+rd(weekday=MO(-1))] = "Victoria Day"
            elif self.prov == 'QC' and year >= 1953:
                self[date(year,5,24)+rd(weekday=MO(-1))] = "National Patriotes Day"

            # National Aboriginal Day
            if self.prov == 'NT' and year >= 1996:
                self[date(year,6,21)] = "National Aboriginal Day"

            # St. Jean Baptiste Day
            if self.prov == 'QC' and year >= 1925:
                self[date(year,6,24)] = "St. Jean Baptiste Day"
                if self.observed and date(year,6,24).weekday() == 6:
                    self[date(year,6,25)] = "St. Jean Baptiste Day (Observed)"

            # Discovery Day
            if self.prov == 'NL' and year >= 1997:
                dt = date(year,6,24)
                # Nearest Monday to June 24
                dt1 = dt+rd(weekday=MO(-1))
                dt2 = dt+rd(weekday=MO(+1))
                if dt2 - dt <= dt - dt1:
                    self[dt2] = "Discovery Day"
                else:
                    self[dt1] = "Discovery Day"
            elif self.prov == 'YU' and year >= 1912:
                self[date(year,8,1)+rd(weekday=MO(+3))] = "Discovery Day"

            # Canada Day / Memorial Day (NL)
            if self.prov != 'NL' and year >= 1867:
                self[date(year,7,1)] = "Canada Day"
                if self.observed and date(year,7,1).weekday() in (5,6):
                    self[date(year,7,1)+rd(weekday=MO)] = "Canada Day (Observed)"
            elif year >= 1867:
                self[date(year,7,1)] = "Memorial Day"
                if self.observed and date(year,7,1).weekday() in (5,6):
                    self[date(year,7,1)+rd(weekday=MO)] = "Memorial Day (Observed)"

            # Nunavut Day
            if self.prov == 'NU' and year >= 2001:
                self[date(year,7,9)] = "Nunavut Day"
                if self.observed and date(year,7,9).weekday() == 6:
                    self[date(year,7,10)] = "Nunavut Day (Observed)"
            elif self.prov == 'NU' and year == 2000:
                self[date(2000,4,1)] = "Nunavut Day"

            # Civic Holiday
            if self.prov in ('SK','ON','MB','NT') and year >= 1900:
                self[date(year,8,1)+rd(weekday=MO)] = "Civic Holiday"
            elif self.prov in ('BC') and year >= 1974:
                self[date(year,8,1)+rd(weekday=MO)] = "British Columbia Day"

            # Labour Day
            if year >= 1894:
                self[date(year,9,1)+rd(weekday=MO)] = "Labour Day"

            # Thanksgiving
            if self.prov not in ('NB','NS','PE','NL') and year >= 1931:
                self[date(year,10,1)+rd(weekday=MO(+2))] = "Thanksgiving"

            # Remembrance Day
            if self.prov not in ('ON','QC','NS','NL','NT','PE','SK') and year >= 1931:
                self[date(year,11,11)] = "Remembrance Day"
            elif self.prov in ('NS','NL','NT','PE','SK') and year >= 1931:
                self[date(year,11,11)] = "Remembrance Day"
                if self.observed and date(year,11,11).weekday() == 6:
                    self[date(year,11,11)+rd(weekday=MO)] = "Remembrance Day (Observed)"

            # Christmas Day
            if year >= 1867:
                self[date(year,12,25)] = "Christmas Day"
                if self.observed and date(year,12,25).weekday() == 5:
                    self[date(year,12,24)] = "Christmas Day (Observed)"
                elif self.observed and date(year,12,25).weekday() == 6:
                    self[date(year,12,26)] = "Christmas Day (Observed)"

            # Boxing Day
            if year >= 1867:
                if self.observed and date(year,12,26).weekday() in (5,6):
                    self[date(year,12,26)+rd(weekday=MO)] = "Boxing Day (Observed)"
                elif self.observed and date(year,12,26).weekday() == 0:
                    self[date(year,12,27)] = "Boxing Day (Observed)"
                else:
                    self[date(year,12,26)] = "Boxing Day"
Exemple #44
0
    def rebuild(self, year, month):
        # Every mask is 7 days longer to handle cross-year weekly periods.
        rr = self.rrule
        if year != self.lastyear:
            self.yearlen = 365+calendar.isleap(year)
            self.nextyearlen = 365+calendar.isleap(year+1)
            firstyday = datetime.date(year, 1, 1)
            self.yearordinal = firstyday.toordinal()
            self.yearweekday = firstyday.weekday()

            wday = datetime.date(year, 1, 1).weekday()
            if self.yearlen == 365:
                self.mmask = M365MASK
                self.mdaymask = MDAY365MASK
                self.nmdaymask = NMDAY365MASK
                self.wdaymask = WDAYMASK[wday:]
                self.mrange = M365RANGE
            else:
                self.mmask = M366MASK
                self.mdaymask = MDAY366MASK
                self.nmdaymask = NMDAY366MASK
                self.wdaymask = WDAYMASK[wday:]
                self.mrange = M366RANGE

            if not rr._byweekno:
                self.wnomask = None
            else:
                self.wnomask = [0]*(self.yearlen+7)
                # no1wkst = firstwkst = self.wdaymask.index(rr._wkst)
                no1wkst = firstwkst = (7-self.yearweekday+rr._wkst)%7
                if no1wkst >= 4:
                    no1wkst = 0
                    # Number of days in the year, plus the days we got
                    # from last year.
                    wyearlen = self.yearlen+(self.yearweekday-rr._wkst)%7
                else:
                    # Number of days in the year, minus the days we
                    # left in last year.
                    wyearlen = self.yearlen-no1wkst
                div, mod = divmod(wyearlen, 7)
                numweeks = div+mod//4
                for n in rr._byweekno:
                    if n < 0:
                        n += numweeks+1
                    if not (0 < n <= numweeks):
                        continue
                    if n > 1:
                        i = no1wkst+(n-1)*7
                        if no1wkst != firstwkst:
                            i -= 7-firstwkst
                    else:
                        i = no1wkst
                    for j in range(7):
                        self.wnomask[i] = 1
                        i += 1
                        if self.wdaymask[i] == rr._wkst:
                            break
                if 1 in rr._byweekno:
                    # Check week number 1 of next year as well
                    # TODO: Check -numweeks for next year.
                    i = no1wkst+numweeks*7
                    if no1wkst != firstwkst:
                        i -= 7-firstwkst
                    if i < self.yearlen:
                        # If week starts in next year, we
                        # don't care about it.
                        for j in range(7):
                            self.wnomask[i] = 1
                            i += 1
                            if self.wdaymask[i] == rr._wkst:
                                break
                if no1wkst:
                    # Check last week number of last year as
                    # well. If no1wkst is 0, either the year
                    # started on week start, or week number 1
                    # got days from last year, so there are no
                    # days from last year's last week number in
                    # this year.
                    if -1 not in rr._byweekno:
                        lyearweekday = datetime.date(year-1, 1, 1).weekday()
                        lno1wkst = (7-lyearweekday+rr._wkst)%7
                        lyearlen = 365+calendar.isleap(year-1)
                        if lno1wkst >= 4:
                            lno1wkst = 0
                            lnumweeks = 52+(lyearlen+
                                           (lyearweekday-rr._wkst)%7)%7//4
                        else:
                            lnumweeks = 52+(self.yearlen-no1wkst)%7//4
                    else:
                        lnumweeks = -1
                    if lnumweeks in rr._byweekno:
                        for i in range(no1wkst):
                            self.wnomask[i] = 1

        if (rr._bynweekday and
            (month != self.lastmonth or year != self.lastyear)):
            ranges = []
            if rr._freq == YEARLY:
                if rr._bymonth:
                    for month in rr._bymonth:
                        ranges.append(self.mrange[month-1:month+1])
                else:
                    ranges = [(0, self.yearlen)]
            elif rr._freq == MONTHLY:
                ranges = [self.mrange[month-1:month+1]]
            if ranges:
                # Weekly frequency won't get here, so we may not
                # care about cross-year weekly periods.
                self.nwdaymask = [0]*self.yearlen
                for first, last in ranges:
                    last -= 1
                    for wday, n in rr._bynweekday:
                        if n < 0:
                            i = last+(n+1)*7
                            i -= (self.wdaymask[i]-wday)%7
                        else:
                            i = first+(n-1)*7
                            i += (7-self.wdaymask[i]+wday)%7
                        if first <= i <= last:
                            self.nwdaymask[i] = 1

        if rr._byeaster:
            self.eastermask = [0]*(self.yearlen+7)
            eyday = easter.easter(year).toordinal()-self.yearordinal
            for offset in rr._byeaster:
                self.eastermask[eyday+offset] = 1

        self.lastyear = year
        self.lastmonth = month
Exemple #45
0
def calc_easter(year):
    """returns the date of Easter Sunday of the given yyyy year"""
    y = year
    # golden year - 1
    g = y % 19
    # offset
    e = 0
    # century
    c = y/100
    # h is (23 - Epact) mod 30
    h = (c-c/4-(8*c+13)/25+19*g+15)%30
    # number of days from March 21 to Paschal Full Moon
    i = h-(h/28)*(1-(h/28)*(29/(h+1))*((21-g)/11))
    # weekday for Paschal Full Moon (0=Sunday)
    j = (y+y/4+i+2-c+c/4)%7
    # number of days from March 21 to Sunday on or before Paschal Full Moon
    # p can be from -6 to 28
    p = i-j+e
    d = 1+(p+27+(p+6)/40)%31
    m = 3+(p+26)/30
    return datetime.date(y,m,d)


# test the calc_easter function
if __name__ == '__main__':
    for y in range(1970,2100):
        e = calc_easter(y)
        print e
        if check:
            assert e == easter(y), '%s != %s' % (e, easter(y))
    def _populate(self, year):
        # New Year's Day
        self[date(year, JAN, 1)] = "New Year's Day"

        # Unity Day
        name = "Unity Day"
        self[date(year, FEB, 5)] = name
        if date(year, FEB, 5).weekday() == SUN:
            self[date(year, FEB, 6)] = name + " (Observed)"

        # President Ntaryamira Day
        name = "President Ntaryamira Day"
        self[date(year, APR, 6)] = "President Ntaryamira Day"
        if date(year, APR, 6).weekday() == SUN:
            self[date(year, APR, 7)] = name + " (Observed)"

        # Labour Day
        name = "Labour Day"
        self[date(year, MAY, 1)] = name
        if date(year, MAY, 1).weekday() == SUN:
            self[date(year, MAY, 2)] = name + " (Observed)"

        # Ascension Day
        name = "Ascension Day"
        self[easter(year) + rd(days=+39)] = name

        # Independence Day post 1962
        name = "Independence Day"
        if year > 1961:
            self[date(year, JUL, 1)] = name
            if date(year, JUL, 1).weekday() == SUN:
                self[date(year, JUL, 2)] = name + " (Observed)"

        # Eid Al Adha- Feast of the Sacrifice
        # date of observance is announced yearly
        for date_obs in get_gre_date(year, 12, 10):
            hol_date = date_obs
            self[hol_date] = "Eid Al Adha"
            self[hol_date + rd(days=1)] = "Eid Al Adha"

        # Assumption Day
        name = "Assumption Day"
        self[date(year, AUG, 15)] = name

        # Prince Louis Rwagasore Day
        name = "Prince Louis Rwagasore Day"
        self[date(year, OCT, 13)] = name
        if date(year, OCT, 13).weekday() == SUN:
            self[date(year, OCT, 14)] = name + " (Observed)"

        # President Ndadaye's Day
        name = "President Ndadaye's Day"
        self[date(year, OCT, 21)] = name
        if date(year, OCT, 21).weekday() == SUN:
            self[date(year, OCT, 22)] = name + " (Observed)"

        # All Saints' Day
        name = "All Saints' Day"
        self[date(year, NOV, 1)] = name
        if date(year, NOV, 1).weekday() == SUN:
            self[date(year, NOV, 2)] = name + " (Observed)"

        # Christmas Day
        self[date(year, DEC, 25)] = "Christmas Day"
def get_german_holidays(year, place=[None, None, None], scope='legal'):
    r"""
    Returns German holiday dates. Use the abbreviations for the german
    federal states like 'BY' for Bayern.

    Parameters
    ----------
    year : int
        Year of which the holidays are wanted
    place : list of strings
        List of names: [country, state, city]
    scope : string
        Type of holidays. So far only legal is possible.

    Returns
    -------
    dictionary
        The keys are in the datetime format the values represent the names.

    Notes
    -----
    So far only the data of german holidays is available. Feel free to add
    other countries or to implement workalendar.
    https://github.com/novapost/workalendar

    Examples
    --------
    get_holidays(2015, place=['Germany', 'BE', 'Berlin'])
    """
    logging.debug('Feiertage für: {0}'.format(place))
    if place[0] not in ['Deutschland', 'deutschland', 'Germany', 'germany']:
        logging.error(
            'You are outside of Germany. The holidays will be incorrect.')
    # Determine Easter
    eastr = easter.easter(year)

    # Add national holidays
    adict = {
        date(year,  1,  1): 'Neujahr',
        date(year,  5,  1): 'Tag der Arbeit',
        date(year, 10,  3): 'Tag der Deutschen Einheit',
        date(year, 12, 25): '1. Weihnachtstag',
        date(year, 12, 26): '2. Weihnachtstag',
        eastr - timedelta(days=2): 'Karfreitag',
        eastr: 'Ostersonntag',
        eastr + timedelta(days=1): 'Ostermontag',
        eastr + timedelta(days=39): 'Christi Himmelfahrt',
        eastr + timedelta(days=50): 'Pfingstmontag',
        }

    # Add federal holidays
    if place[1].upper() in ('BW', 'BY', 'ST'):
        adict[date(year, 1, 6)] = 'Heilige Drei Könige'

    if place[1] in ('BW', 'BY', 'HE', 'NW', 'RP', 'SL'):
        adict[eastr + timedelta(days=60)] = 'Frohnleichnam'

    if place[1].upper() in ('BY', 'SL'):
        adict[date(year, 8, 15)] = 'Mariä Himmelfahrt'

    if place[1].upper() in ('BB', 'MV', 'SN', 'ST', 'TH'):
        adict[date(year, 10, 31)] = 'Reformationstag'

    if place[1].upper() in ('BW', 'BY', ):
        adict[date(year, 11, 1)] = 'Allerheiligen'

    return adict
def holiday(date):
    """
    Return if the given date is a holiday.

    Args:
        date (datetime.date): The date for which to check if it's a holiday.

    Returns:
        str: The Dutch name of the holiday on that date or an empty string.

    """
    # Simple hardcoded dates
    if date.month == 1:
        if date.day == 1:
            return 'Nieuwjaar'
        if date.day == 6:
            return 'Drie Koningen'
    if date.month == 2:
        if date.day == 14:
            return 'Valentijn'
    if date.month == 4:
        if date.day == 27:
            return 'Koningsdag'
    if date.month == 5:
        if date.day == 4:
            return 'Dodenherdenking'
        if date.day == 5:
            return 'Bevrijdingsdag'
    if date.month == 7:
        if date.day == 29:
            return 'Frikandellendag'
    if date.month == 10:
        if date.day == 4:
            return 'Dierendag'
    if date.month == 12:
        if date.day == 5:
            return 'Sinterklaas'
        if date.day == 25:
            return 'Eerste Kerstdag'
        if date.day == 26:
            return 'Tweede Kerstdag'
        if date.day == 31:
            return 'Oudjaar'

    # Nth sunday of month
    if date.month == 3 and date.weekday() == 6 and date.day > 24:
        return ('Zomertijd\n'
                'Vergeet niet je klok niet een uur vooruit te zetten!')
    if date.month == 5 and date.weekday() == 6 and 7 < date.day < 15:
        return 'Moederdag'
    if date.month == 6 and date.weekday() == 6 and 14 < date.day < 22:
        return 'Vaderdag'
    if date.month == 9 and date.weekday() == 1 and 15 < date.day < 23:
        return 'Prinsjesdag'
    if date.month == 10 and date.weekday() == 6 and date.day > 24:
        return 'Wintertijd\nVergeet niet je klok een uur terug te zetten!'

    # Easte related
    easter_date = easter.easter(date.year)
    if date == easter_date:
        return 'Eerste Paasdag'
    if date == easter_date + datetime.timedelta(days=-2):
        return 'Goede Vrijdag'
    if date == easter_date + datetime.timedelta(days=1):
        return 'Tweede Paasdag'
    if date == easter_date + datetime.timedelta(days=39):
        return 'Hemelvaart'
    if date == easter_date + datetime.timedelta(days=49):
        return 'Eerste Pinksterdag'
    if date == easter_date + datetime.timedelta(days=50):
        return 'Tweede Pinksterdag'

    carnaval_date = easter_date
    i = 40  # Carnaval is 40 days before easter
    while i:
        # Sundays don't count towards these 40 days
        if carnaval_date.weekday() != 6:
            i -= 1
        carnaval_date -= datetime.timedelta(days=1)
    for i in range(3):
        if date == carnaval_date - datetime.timedelta(days=i):
            return 'Carnaval'
    return ''
    def _populate(self, year):
        # New Year's Day (Law 2.977)
        self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]"
        # Day after, if it's a Sunday (Law 20.983)
        if year > 2016 and date(year, JAN, 1).weekday() == SUN:
            self[date(year, JAN, 2)] = "Fiestas Patrias [Holiday]"

        # Holy Week (Law 2.977)
        name_fri = "Semana Santa (Viernes Santo) [Good Friday)]"
        name_sat = "Semana Santa (Sábado Santo) [Good Saturday)]"
        name_easter = 'Día de Pascuas [Easter Day]'

        self[easter(year) + rd(weekday=FR(-1))] = name_fri
        self[easter(year) + rd(weekday=SA(-1))] = name_sat
        self[easter(year)] = name_easter

        # Labor Day (Law 2.200, renamed with Law 18.018)
        name = "Día Nacional del Trabajo [Labour Day]"
        self[date(year, MAY, 1)] = name

        # Naval Glories Day (Law 2.977)
        name = "Día de las Glorias Navales [Navy Day]"
        self[date(year, MAY, 21)] = name

        # Saint Peter and Saint Paul (Law 18.432)
        name = "San Pedro y San Pablo [Saint Peter and Saint Paul]"
        if year < 2020:
            self[date(year, JUN, 29)] = name
        else:
            # floating Monday holiday (Law 19.668)
            if date(year, JUN, 29).weekday() <= THU:
                self[date(year, JUN, 29) +
                     rd(date(year, JUN, 29), weekday=MO(-1))] = name
            elif date(year, JUN, 29).weekday() == FRI:
                self[date(year, JUN, 29) + rd(weekday=MO)] = name
            else:
                self[date(year, JUN, 29)] = name

        # Day of Virgin of Carmen (Law 20.148)
        if year > 2006:
            name = "Virgen del Carmen [Our Lady of Mount Carmel]"
            self[date(year, JUL, 16)] = name

        # Day of Assumption of the Virgin (Law 2.977)
        name = "Asunción de la Virgen [Assumption of Mary]"
        self[date(year, AUG, 15)] = name

        # National Holiday Friday preceding Independence Day (Law 20.983)
        if year > 2016 and date(year, SEP, 18).weekday() == SAT:
            self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]"

        # National Holiday Monday preceding Independence Day (Law 20.215)
        if year > 2007 and date(year, SEP, 18).weekday() == TUE:
            self[date(year, SEP, 17)] = "Fiestas Patrias [Holiday]"

        # Independence Day (Law 2.977)
        name = "Día de la Independencia [Independence Day]"
        self[date(year, SEP, 18)] = name

        # Day of Glories of the Army of Chile (Law 2.977)
        name = "Día de las Glorias del Ejército [Army Day]"
        self[date(year, SEP, 19)] = name

        # National Holiday Friday following Army Day (Law 20.215)
        if year > 2007 and date(year, SEP, 19).weekday() == THU:
            self[date(year, SEP, 20)] = "Fiestas Patrias [Holiday]"

        # Day of the Meeting of Two Worlds (Law 3.810)
        if year < 2010:
            self[date(year, OCT, 12)] = "Día de la Raza [Columbus day]"
        elif year < 2020:
            self[date(year, OCT, 12)] = "Día del Respeto a la Diversidad"\
                                        " [Day of the Meeting " \
                                        " of Two Worlds]"
        else:
            # floating Monday holiday (Law 19.668)
            name = ("Día del Descubrimiento de dos Mundos [Columbus Day]")
            if date(year, OCT, 12).weekday() <= THU:
                self[date(year, OCT, 12) +
                     rd(date(year, OCT, 12), weekday=MO(-1))] = name
            elif date(year, OCT, 12).weekday() == FRI:
                self[date(year, OCT, 12) + rd(weekday=MO)] = name
            else:
                self[date(year, OCT, 12)] = name

        # National Day of the Evangelical and Protestant Churches (Law 20.299)
        if year > 2007:
            name = ("Día Nacional de las Iglesias Evangélicas y Protestantes "
                    " [Reformation Day]")
            self[date(year, OCT, 31)] = name

        # All Saints Day (Law 2.977)
        name = "Día de Todos los Santos [All Saints Day]"
        self[date(year, NOV, 1)] = name

        # Immaculate Conception (Law 2.977)
        self[date(year, DEC, 8)] = "La Inmaculada Concepción" \
                                   " [Immaculate Conception]"

        # Christmas (Law 2.977)
        self[date(year, DEC, 25)] = "Navidad [Christmas]"

        # región de Arica y Parinacota
        if self.state == 'AP' and year >= 2020:
            # Law 20.663
            self[date(year, JUN, 7)] = ("Asalto y Toma del Morro de Arica"
                                        " [Assault and Capture of Cape Arica]")

        # región de Ñuble
        if self.state == 'NB' and year >= 2014:
            # Law 20.678
            self[date(year, AUG, 20)] =\
                ("Nacimiento del Prócer de la Independencia"
                 " (Chillán y Chillán Viejo)"
                 " [Nativity of Bernardo O'Higgins]")
    def _populate(self, year):

        # New Year's Day
        name = "ახალი წელი"
        self[date(year, JAN, 1)] = name

        # New Year's Day
        name = "ბედობა"
        self[date(year, JAN, 2)] = name

        # Christmas Day (Orthodox)
        name = "ქრისტეშობა"
        self[date(year, JAN, 7)] = name

        # Baptism Day of our Lord Jesus Christ
        name = "ნათლისღება"
        self[date(year, JAN, 19)] = name

        # Mother's Day
        name = "დედის დღე"
        self[date(year, MAR, 3)] = name

        # Women's Day
        name = "ქალთა საერთაშორისო დღე"
        self[date(year, MAR, 8)] = name

        # Orthodox Good Friday
        name = "წითელი პარასკევი"
        self[easter(year, method=EASTER_ORTHODOX) - rd(days=2)] = name

        # Orthodox Holy Saturday
        name = "დიდი შაბათი"
        self[easter(year, method=EASTER_ORTHODOX) - rd(days=1)] = name

        # 	Orthodox Easter Sunday
        name = "აღდგომა"
        self[easter(year, method=EASTER_ORTHODOX)] = name

        # Orthodox Easter Monday
        name = "შავი ორშაბათი"
        self[easter(year, method=EASTER_ORTHODOX) + rd(days=1)] = name

        # National Unity Day
        name = "ეროვნული ერთიანობის დღე"
        self[date(year, APR, 9)] = name

        # Day of Victory
        name = "ფაშიზმზე გამარჯვების დღე"
        self[date(year, MAY, 9)] = name

        # Saint Andrew the First-Called Day
        name = "წმინდა ანდრია პირველწოდებულის დღე"
        self[date(year, MAY, 12)] = name

        # Independence Day
        name = "დამოუკიდებლობის დღე"
        self[date(year, MAY, 26)] = name

        # Saint Mary's Day
        name = "მარიამობა"
        self[date(year, AUG, 28)] = name

        # Day of Svetitskhoveli Cathedral
        name = "სვეტიცხოვლობა"
        self[date(year, OCT, 14)] = name

        # Saint George's Day
        name = "გიორგობა"
        self[date(year, NOV, 23)] = name
Exemple #51
0
    def _populate(self, year):
        self._is_observed(date(year, JAN, 1), "Año nuevo")
        self._is_observed(date(year, JAN, 6), "Epifanía del Señor")

        if (year < 2015 and self.prov and self.prov in [
                "AR",
                "CL",
                "CM",
                "EX",
                "GA",
                "MD",
                "ML",
                "MC",
                "NC",
                "PV",
                "VC",
        ]):
            self._is_observed(date(year, MAR, 19), "San José")
        elif (year == 2015 and self.prov
              and self.prov in ["CM", "MD", "ML", "MC", "NC", "PV", "VC"]):
            self._is_observed(date(year, MAR, 19), "San José")
        elif (year == 2016 and self.prov
              and self.prov in ["ML", "MC", "PV", "VC"]):
            self._is_observed(date(year, MAR, 19), "San José")
        elif year == 2017 and self.prov and self.prov in ["PV"]:
            self._is_observed(date(year, MAR, 19), "San José")
        elif (2018 <= year <= 2019 and self.prov
              and self.prov in ["GA", "MC", "NC", "PV", "VC"]):
            self._is_observed(date(year, MAR, 19), "San José")
        elif (2020 <= year <= 2025 and self.prov
              and self.prov in ["CM", "GA", "MC", "NC", "PV", "VC"]):
            self._is_observed(date(year, MAR, 19), "San José")
        if self.prov and self.prov not in ["CT", "VC"]:
            self[easter(year) + rd(weeks=-1, weekday=TH)] = "Jueves Santo"
            self[easter(year) + rd(weeks=-1, weekday=FR)] = "Viernes Santo"
        if self.prov and self.prov in ["CT", "PV", "NC", "VC", "IB", "CM"]:
            self[easter(year) + rd(weekday=MO)] = "Lunes de Pascua"
        self._is_observed(date(year, MAY, 1), "Día del Trabajador")
        if self.prov and self.prov in ["CT", "GA", "VC"]:
            self._is_observed(date(year, JUN, 24), "San Juan")
        self._is_observed(date(year, AUG, 15), "Asunción de la Virgen")
        self._is_observed(date(year, OCT, 12), "Día de la Hispanidad")
        self._is_observed(date(year, NOV, 1), "Todos los Santos")
        self._is_observed(date(year, DEC, 6), "Día de la Constitución "
                          "Española")
        self._is_observed(date(year, DEC, 8), "La Inmaculada Concepción")
        self._is_observed(date(year, DEC, 25), "Navidad")
        if self.prov and self.prov in ["CT", "IB"]:
            self._is_observed(date(year, DEC, 26), "San Esteban")
        # Provinces festive day
        if self.prov:
            if self.prov == "AN":
                self._is_observed(date(year, FEB, 28), "Día de Andalucia")
            elif self.prov == "AR":
                self._is_observed(date(year, APR, 23), "Día de San Jorge")
            elif self.prov == "AS":
                self._is_observed(date(year, SEP, 8), "Día de Asturias")
            elif self.prov == "CB":
                self._is_observed(
                    date(year, JUL, 28),
                    "Día de las Instituci"
                    "ones de Cantabria",
                )
            elif self.prov == "CM":
                self._is_observed(date(year, MAY, 31), "Día de Castilla "
                                  "La Mancha")
            elif self.prov == "CL":
                self._is_observed(date(year, APR, 23), "Día de Castilla y "
                                  "Leon")
            elif self.prov == "CT":
                self._is_observed(date(year, SEP, 11), "Día Nacional de "
                                  "Catalunya")
            elif self.prov == "VC":
                self._is_observed(date(year, OCT, 9), "Día de la Comunidad "
                                  "Valenciana")
            elif self.prov == "EX":
                self._is_observed(date(year, SEP, 8), "Día de Extremadura")
            elif self.prov == "GA":
                self._is_observed(date(year, JUL, 25), "Día Nacional de "
                                  "Galicia")
            elif self.prov == "IB":
                self._is_observed(date(year, MAR, 1), "Día de las Islas "
                                  "Baleares")
            elif self.prov == "CN":
                self._is_observed(date(year, MAY, 30), "Día de Canarias")
            elif self.prov == "MD":
                self._is_observed(date(year, MAY, 2), "Día de Comunidad de "
                                  "Madrid")
            elif self.prov == "MC":
                self._is_observed(date(year, JUN, 9), "Día de la Región de "
                                  "Murcia")
            elif self.prov == "NC":
                self._is_observed(date(year, SEP, 27), "Día de Navarra")
            elif self.prov == "PV":
                self._is_observed(date(year, OCT, 25), "Día del Páis Vasco")
            elif self.prov == "RI":
                self._is_observed(date(year, JUN, 9), "Día de La Rioja")
Exemple #52
0
import datetime
import numpy as np

import psycopg2
COOP = psycopg2.connect(database='coop', host='iemdb', user='******')
cursor = COOP.cursor()

cursor.execute("""SELECT day, high from alldata_ia where station = 'IA2203'""")
data = {}
for row in cursor:
    data[ row[0] ] = row[1]

highs = []

for yr in range(1880,2014):
    e = easter(yr)
    highs.append( data[e] )
highs.append( 84 )
highs = np.array(highs)

import matplotlib.pyplot as plt

(fig, ax) = plt.subplots(1,1)

bars = ax.bar(np.arange(1880,2015), highs, fc='b', ec='b')
for i, bar in enumerate(bars):
    if highs[i] >= highs[-1]:
        ax.text( 1880+i, highs[i] + 1, "%s\n%s" % (highs[i], 1880+i), ha='center', va='bottom')
        bars[i].set_facecolor('r')
        bars[i].set_edgecolor('r')
ax.grid(True)
Exemple #53
0
    def _populate(self, year):

        day_following = "The day following "

        # The first day of January
        name = "The first day of January"
        first_date = date(year, JAN, 1)
        if self.observed:
            if first_date.weekday() == SUN:
                self[first_date +
                     rd(days=+1)] = day_following + self.first_lower(name)
                first_date = first_date + rd(days=+1)
            else:
                self[first_date] = name
        else:
            self[first_date] = name

        # Lunar New Year
        name = "Lunar New Year's Day"
        preceding_day_lunar = "The day preceding Lunar New Year's Day"
        second_day_lunar = "The second day of Lunar New Year"
        third_day_lunar = "The third day of Lunar New Year"
        fourth_day_lunar = "The fourth day of Lunar New Year"
        dt = self.cnls.lunar_n_y_date(year)
        new_year_date = date(dt.year, dt.month, dt.day)
        if self.observed:
            self[new_year_date] = name
            if new_year_date.weekday() in [MON, TUE, WED, THU]:
                self[new_year_date] = name
                self[new_year_date + rd(days=+1)] = second_day_lunar
                self[new_year_date + rd(days=+2)] = third_day_lunar
            elif new_year_date.weekday() == FRI:
                self[new_year_date] = name
                self[new_year_date + rd(days=+1)] = second_day_lunar
                self[new_year_date + rd(days=+3)] = fourth_day_lunar
            elif new_year_date.weekday() == SAT:
                self[new_year_date] = name
                self[new_year_date + rd(days=+2)] = third_day_lunar
                self[new_year_date + rd(days=+3)] = fourth_day_lunar
            elif new_year_date.weekday() == SUN:
                if year in [2006, 2007, 2010]:
                    self[new_year_date + rd(days=-1)] = preceding_day_lunar
                    self[new_year_date + rd(days=+1)] = second_day_lunar
                    self[new_year_date + rd(days=+2)] = third_day_lunar
                else:
                    self[new_year_date + rd(days=+1)] = second_day_lunar
                    self[new_year_date + rd(days=+2)] = third_day_lunar
                    self[new_year_date + rd(days=+3)] = fourth_day_lunar
        else:
            self[new_year_date] = name
            self[new_year_date + rd(days=+1)] = second_day_lunar
            self[new_year_date + rd(days=+2)] = third_day_lunar

        # Ching Ming Festival
        name = "Ching Ming Festival"
        if self.is_leap_year(year) or (self.is_leap_year(year - 1)
                                       and year > 2008):
            ching_ming_date = date(year, APR, 4)
        else:
            ching_ming_date = date(year, APR, 5)
        if self.observed:
            if ching_ming_date.weekday() == SUN:
                self[ching_ming_date + rd(days=+1)] = day_following + name
                ching_ming_date = ching_ming_date + rd(days=+1)
            else:
                self[ching_ming_date] = name
        else:
            self[ching_ming_date] = name

        # Easter Holiday
        good_friday = "Good Friday"
        easter_monday = "Easter Monday"
        if self.observed:
            self[easter(year) + rd(weekday=FR(-1))] = good_friday
            self[easter(year) + rd(weekday=SA(-1))] = (day_following +
                                                       good_friday)
            if ching_ming_date == easter(year) + rd(weekday=MO):
                self[easter(year) + rd(weekday=MO) +
                     rd(days=+1)] = (day_following + easter_monday)
            else:
                self[easter(year) + rd(weekday=MO)] = easter_monday
        else:
            self[easter(year) + rd(weekday=FR(-1))] = good_friday
            self[easter(year) + rd(weekday=SA(-1))] = (day_following +
                                                       good_friday)
            self[easter(year) + rd(weekday=MO)] = easter_monday

        # Birthday of the Buddha
        name = "Birthday of the Buddha"
        dt = self.cnls.lunar_to_gre(year, 4, 8)
        buddha_date = date(dt.year, dt.month, dt.day)
        if self.observed:
            if buddha_date.weekday() == SUN:
                self[buddha_date + rd(days=+1)] = day_following + name
            else:
                self[buddha_date] = name
        else:
            self[buddha_date] = name

        # Labour Day
        name = "Labour Day"
        labour_date = date(year, MAY, 1)
        if self.observed:
            if labour_date.weekday() == SUN:
                self[labour_date + rd(days=+1)] = day_following + name
            else:
                self[labour_date] = name
        else:
            self[labour_date] = name

        # Tuen Ng Festival
        name = "Tuen Ng Festival"
        dt = self.cnls.lunar_to_gre(year, 5, 5)
        tuen_ng_date = date(dt.year, dt.month, dt.day)
        if self.observed:
            if tuen_ng_date.weekday() == SUN:
                self[tuen_ng_date + rd(days=+1)] = day_following + name
            else:
                self[tuen_ng_date] = name
        else:
            self[tuen_ng_date] = name

        # Hong Kong Special Administrative Region Establishment Day
        name = "Hong Kong Special Administrative Region Establishment Day"
        hksar_date = date(year, JUL, 1)
        if self.observed:
            if hksar_date.weekday() == SUN:
                self[hksar_date + rd(days=+1)] = day_following + name
            else:
                self[hksar_date] = name
        else:
            self[hksar_date] = name

        # Special holiday on 2015 - The 70th anniversary day of the victory
        # of the Chinese people's war of resistance against Japanese aggression
        name = ("The 70th anniversary day of the victory of the Chinese " +
                "people's war of resistance against Japanese aggression")
        if year == 2015:
            self[date(year, SEP, 3)] = name

        # Chinese Mid-Autumn Festival
        name = "Chinese Mid-Autumn Festival"
        dt = self.cnls.lunar_to_gre(year, 8, 15)
        mid_autumn_date = date(dt.year, dt.month, dt.day)
        if self.observed:
            if mid_autumn_date.weekday() == SAT:
                self[mid_autumn_date] = name
            else:
                self[mid_autumn_date + rd(days=+1)] = (day_following + "the " +
                                                       name)
            mid_autumn_date = mid_autumn_date + rd(days=+1)
        else:
            self[mid_autumn_date] = name

        # National Day
        name = "National Day"
        national_date = date(year, OCT, 1)
        if self.observed:
            if (national_date.weekday() == SUN
                    or national_date == mid_autumn_date):
                self[national_date + rd(days=+1)] = day_following + name
            else:
                self[national_date] = name
        else:
            self[national_date] = name

        # Chung Yeung Festival
        name = "Chung Yeung Festival"
        dt = self.cnls.lunar_to_gre(year, 9, 9)
        chung_yeung_date = date(dt.year, dt.month, dt.day)
        if self.observed:
            if chung_yeung_date.weekday() == SUN:
                self[chung_yeung_date + rd(days=+1)] = day_following + name
            else:
                self[chung_yeung_date] = name
        else:
            self[chung_yeung_date] = name

        # Christmas Day
        name = "Christmas Day"
        first_after_christmas = "The first weekday after " + name
        second_after_christmas = "The second weekday after " + name
        christmas_date = date(year, DEC, 25)
        if self.observed:
            if christmas_date.weekday() == SUN:
                self[christmas_date] = name
                self[christmas_date + rd(days=+1)] = first_after_christmas
                self[christmas_date + rd(days=+2)] = second_after_christmas
            elif christmas_date.weekday() == SAT:
                self[christmas_date] = name
                self[christmas_date + rd(days=+2)] = first_after_christmas
            else:
                self[christmas_date] = name
                self[christmas_date + rd(days=+1)] = first_after_christmas
        else:
            self[christmas_date] = name
            self[christmas_date + rd(days=+1)] = day_following + name
Exemple #54
0
    def OnBoutonOk(self, event):
        # Récupération des années
        annee_depart = self.ctrl_annee.GetValue()
        nbre_annees = self.ctrl_nbre.GetValue()

        # Génération de la liste des années :
        listeAnnees = range(annee_depart, annee_depart + nbre_annees)

        # Récupération jours fériés à créer
        listeCoches = []
        for index in range(0, self.ctrl_jours.GetCount()):
            if self.ctrl_jours.IsChecked(index):
                listeCoches.append(index)

        if len(listeCoches) == 0:
            dlg = wx.MessageDialog(
                self,
                _(u"Vous devez obligatoirement cocher au moins un jour férié à créer !"
                  ), _(u"Erreur"), wx.OK | wx.ICON_EXCLAMATION)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        # Récupération des jours déjà présents dans la base de données
        DB = GestionDB.DB()
        req = """SELECT IDferie, nom, jour, mois, annee
        FROM jours_feries
        WHERE type='variable' ; """
        DB.ExecuterReq(req)
        listeDonnees = DB.ResultatReq()
        listeJoursExistants = []
        for IDferie, nom, jour, mois, annee in listeDonnees:
            try:
                listeJoursExistants.append(datetime.date(annee, mois, jour))
            except:
                pass

        def SauvegarderDate(nom="", date=None):
            if date not in listeJoursExistants:
                IDferie = DB.ReqInsert("jours_feries", [("type", "variable"),
                                                        ("nom", nom),
                                                        ("annee", date.year),
                                                        ("mois", date.month),
                                                        ("jour", date.day)])

        # Calcul des jours fériés
        for annee in listeAnnees:

            # Dimanche de Paques
            dimanche_paques = easter(annee)

            # Lundi de Pâques
            lundi_paques = dimanche_paques + relativedelta(days=+1)
            if 0 in listeCoches:
                SauvegarderDate(_(u"Lundi de Pâques"), lundi_paques)

            # Ascension
            ascension = dimanche_paques + relativedelta(days=+39)
            if 1 in listeCoches:
                SauvegarderDate(_(u"Jeudi de l'Ascension"), ascension)

            # Pentecote
            pentecote = dimanche_paques + relativedelta(days=+50)
            if 2 in listeCoches:
                SauvegarderDate(_(u"Lundi de Pentecôte"), pentecote)

        DB.Close()

        # Fermeture
        self.EndModal(wx.ID_OK)
Exemple #55
0
    def _populate(self, year):
        # ACT:  Holidays Act 1958
        # NSW:  Public Holidays Act 2010
        # NT:   Public Holidays Act 2013
        # QLD:  Holidays Act 1983
        # SA:   Holidays Act 1910
        # TAS:  Statutory Holidays Act 2000
        # VIC:  Public Holidays Act 1993
        # WA:   Public and Bank Holidays Act 1972

        # TODO do more research on history of Aus holidays

        # New Year's Day
        name = "New Year's Day"
        jan1 = date(year, JAN, 1)
        self[jan1] = name
        if self.observed and jan1.weekday() in WEEKEND:
            self[jan1 + rd(weekday=MO)] = name + " (Observed)"

        # Australia Day
        jan26 = date(year, JAN, 26)
        if year >= 1935:
            if self.prov == "NSW" and year < 1946:
                name = "Anniversary Day"
            else:
                name = "Australia Day"
            self[jan26] = name
            if self.observed and year >= 1946 and jan26.weekday() in WEEKEND:
                self[jan26 + rd(weekday=MO)] = name + " (Observed)"
        elif year >= 1888 and self.prov != "SA":
            name = "Anniversary Day"
            self[jan26] = name

        # Adelaide Cup
        if self.prov == "SA":
            name = "Adelaide Cup"
            if year >= 2006:
                # subject to proclamation ?!?!
                self[date(year, MAR, 1) + rd(weekday=MO(+2))] = name
            else:
                self[date(year, MAR, 1) + rd(weekday=MO(+3))] = name

        # Canberra Day
        # Info from https://www.timeanddate.com/holidays/australia/canberra-day
        # and https://en.wikipedia.org/wiki/Canberra_Day
        if self.prov == "ACT" and year >= 1913:
            name = "Canberra Day"
            if year >= 1913 and year <= 1957:
                self[date(year, MAR, 12)] = name
            elif year >= 1958 and year <= 2007:
                self[date(year, MAR, 1) + rd(weekday=MO(+3))] = name
            elif year >= 2008 and year != 2012:
                self[date(year, MAR, 1) + rd(weekday=MO(+2))] = name
            elif year == 2012:
                self[date(year, MAR, 12)] = name

        # Easter
        self[easter(year) + rd(weekday=FR(-1))] = "Good Friday"
        if self.prov in ("ACT", "NSW", "NT", "QLD", "SA", "VIC"):
            self[easter(year) + rd(weekday=SA(-1))] = "Easter Saturday"
        if self.prov in ("ACT", "NSW", "QLD", "VIC"):
            self[easter(year)] = "Easter Sunday"
        self[easter(year) + rd(weekday=MO)] = "Easter Monday"

        # Anzac Day
        if year > 1920:
            name = "Anzac Day"
            apr25 = date(year, APR, 25)
            self[apr25] = name
            if self.observed:
                if apr25.weekday() == SAT and self.prov in ("WA", "NT"):
                    self[apr25 + rd(weekday=MO)] = name + " (Observed)"
                elif apr25.weekday() == SUN and self.prov in (
                        "ACT",
                        "QLD",
                        "SA",
                        "WA",
                        "NT",
                ):
                    self[apr25 + rd(weekday=MO)] = name + " (Observed)"

        # Western Australia Day
        if self.prov == "WA" and year > 1832:
            if year >= 2015:
                name = "Western Australia Day"
            else:
                name = "Foundation Day"
            self[date(year, JUN, 1) + rd(weekday=MO(+1))] = name

        # Sovereign's Birthday
        if year >= 1952:
            name = "Queen's Birthday"
        elif year > 1901:
            name = "King's Birthday"
        if year >= 1936:
            name = "Queen's Birthday"
            if self.prov == "QLD":
                if year == 2012:
                    self[date(year, JUN, 11)] = "Queen's Diamond Jubilee"
                if year < 2016 and year != 2012:
                    dt = date(year, JUN, 1) + rd(weekday=MO(+2))
                    self[dt] = name
                else:
                    dt = date(year, OCT, 1) + rd(weekday=MO)
                    self[dt] = name
            elif self.prov == "WA":
                # by proclamation ?!?!
                self[date(year, OCT, 1) + rd(weekday=MO(-1))] = name
            elif self.prov in ("NSW", "VIC", "ACT", "SA", "NT", "TAS"):
                dt = date(year, JUN, 1) + rd(weekday=MO(+2))
                self[dt] = name
        elif year > 1911:
            self[date(year, JUN, 3)] = name  # George V
        elif year > 1901:
            self[date(year, NOV, 9)] = name  # Edward VII

        # Picnic Day
        if self.prov == "NT":
            name = "Picnic Day"
            self[date(year, AUG, 1) + rd(weekday=MO)] = name

        # Bank Holiday
        if self.prov == "NSW":
            if year >= 1912:
                name = "Bank Holiday"
                self[date(year, 8, 1) + rd(weekday=MO)] = name

        # Labour Day
        name = "Labour Day"
        if self.prov in ("NSW", "ACT", "SA"):
            self[date(year, OCT, 1) + rd(weekday=MO)] = name
        elif self.prov == "WA":
            self[date(year, MAR, 1) + rd(weekday=MO)] = name
        elif self.prov == "VIC":
            self[date(year, MAR, 1) + rd(weekday=MO(+2))] = name
        elif self.prov == "QLD":
            if 2013 <= year <= 2015:
                self[date(year, OCT, 1) + rd(weekday=MO)] = name
            else:
                self[date(year, MAY, 1) + rd(weekday=MO)] = name
        elif self.prov == "NT":
            name = "May Day"
            self[date(year, MAY, 1) + rd(weekday=MO)] = name
        elif self.prov == "TAS":
            name = "Eight Hours Day"
            self[date(year, MAR, 1) + rd(weekday=MO(+2))] = name

        # Family & Community Day
        if self.prov == "ACT":
            name = "Family & Community Day"
            if 2007 <= year <= 2009:
                self[date(year, NOV, 1) + rd(weekday=TU)] = name
            elif year == 2010:
                # first Monday of the September/October school holidays
                # moved to the second Monday if this falls on Labour day
                # TODO need a formula for the ACT school holidays then
                # http://www.cmd.act.gov.au/communication/holidays
                self[date(year, SEP, 26)] = name
            elif year == 2011:
                self[date(year, OCT, 10)] = name
            elif year == 2012:
                self[date(year, OCT, 8)] = name
            elif year == 2013:
                self[date(year, SEP, 30)] = name
            elif year == 2014:
                self[date(year, SEP, 29)] = name
            elif year == 2015:
                self[date(year, SEP, 28)] = name
            elif year == 2016:
                self[date(year, SEP, 26)] = name
            elif year == 2017:
                self[date(year, SEP, 25)] = name

        # Reconciliation Day
        if self.prov == "ACT":
            name = "Reconciliation Day"
            if year >= 2018:
                self[date(year, 5, 27) + rd(weekday=MO)] = name

        if self.prov == "VIC":
            # Grand Final Day
            if year == 2020:
                # Rescheduled due to COVID-19
                self[date(year, OCT, 23)] = "Grand Final Day"
            elif year == 2021:
                # Rescheduled due to COVID-19
                self[date(year, SEP, 24)] = "Grand Final Day"
            elif year >= 2015:
                self[date(year, SEP, 24) + rd(weekday=FR)] = "Grand Final Day"

            # Melbourne Cup
            self[date(year, NOV, 1) + rd(weekday=TU)] = "Melbourne Cup"

        # The Royal Queensland Show (Ekka)
        # The Show starts on the first Friday of August - providing this is
        # not prior to the 5th - in which case it will begin on the second
        # Friday. The Wednesday during the show is a public holiday.
        if self.prov == "QLD":
            name = "The Royal Queensland Show"
            if year == 2020:
                self[date(year, AUG, 14)] = name
            if year == 2021:
                self[date(year, OCT, 29)] = name
            else:
                self[date(year, AUG, 5) + rd(weekday=FR) +
                     rd(weekday=WE)] = name

        # Christmas Day
        name = "Christmas Day"
        dec25 = date(year, DEC, 25)
        self[dec25] = name
        if self.observed and dec25.weekday() in WEEKEND:
            self[date(year, DEC, 27)] = name + " (Observed)"

        # Boxing Day
        if self.prov == "SA":
            name = "Proclamation Day"
        else:
            name = "Boxing Day"
        dec26 = date(year, DEC, 26)
        self[dec26] = name
        if self.observed and dec26.weekday() in WEEKEND:
            self[date(year, DEC, 28)] = name + " (Observed)"
Exemple #56
0
from dateutil.relativedelta import relativedelta
from dateutil.easter import easter
from dateutil.rrule import rrule, YEARLY, FR
from dateutil.parser import parse

now = parse("Sat Oct 11 17:13:46 UTC 2003")
today = now.date()
print("Today is: %s" % today)
assert str(today) == '2003-10-11'

year = rrule(YEARLY, dtstart=now, bymonth=8,
             bymonthday=13, byweekday=FR)[0].year
rdelta = relativedelta(easter(year), today)

print("Year with next Aug 13th on a Friday is: %s" % year)
assert str(year) == '2004'
print("How far is the Easter of that year: %s" % rdelta)
assert str(rdelta) == 'relativedelta(months=+6)'
print("And the Easter of that year is: %s" % (today+rdelta))
assert str(today+rdelta) == '2004-04-11'
Exemple #57
0
 def get_easter_sunday(self, year):
     "Return the date of the easter (sunday) -- following the easter method"
     return easter.easter(year, self.EASTER_METHOD)
def is_good_friday(date):
    # Defaults to western Easter.
    return date == easter(date.year) - datetime.timedelta(days=2)
    def _populate(self, year):
        # New Year's Day
        if self.observed and date(year, JAN, 1):
            self[date(year, JAN, 1)] = "Año Nuevo [New Year's Day]"

        # The Three Wise Men Day
        if self.observed and date(year, JAN, 6):
            name = "Día de los Reyes Magos [The Three Wise Men Day] (Observed)"
            self[date(year, JAN, 6)] = name

        # The Three Wise Men Day
        if self.observed and date(year, FEB, 3):
            name = "Día de la virgen de Suyapa [Our Lady of Suyapa] (Observed)"
            self[date(year, FEB, 3)] = name

        # The Father's Day
        if self.observed and date(year, MAR, 19):
            name = "Día del Padre [Father's Day] (Observed)"
            self[date(year, MAR, 19)] = name

        # Maundy Thursday
        self[easter(year) +
             rd(weekday=TH(-1))] = "Jueves Santo [Maundy Thursday]"

        # Good Friday
        self[easter(year) + rd(weekday=FR(-1))] = "Viernes Santo [Good Friday]"

        # Holy Saturday
        self[easter(year) +
             rd(weekday=SA(-1))] = "Sábado de Gloria [Holy Saturday]"

        # Easter Sunday
        self[easter(year) +
             rd(weekday=SU(-1))] = "Domingo de Resurrección [Easter Sunday]"

        # America Day
        if self.observed and date(year, APR, 14):
            self[date(year, APR, 14)] = "Día de las Américas [America Day]"

        # Labor Day
        if self.observed and date(year, MAY, 1):
            self[date(year, MAY, 1)] = "Día del Trabajo [Labour Day]"

        # Mother's Day
        may_first = date(int(year), 5, 1)
        weekday_seq = may_first.weekday()
        mom_day = 14 - weekday_seq
        if self.observed and date(year, MAY, mom_day):
            str_day = "Día de la madre [Mother's Day] (Observed)"
            self[date(year, MAY, mom_day)] = str_day

        # Children's Day
        if self.observed and date(year, SEP, 10):
            name = "Día del niño [Children day] (Observed)"
            self[date(year, SEP, 10)] = name

        # Independence Day
        if self.observed and date(year, SEP, 15):
            name = "Día de la Independencia [Independence Day]"
            self[date(year, SEP, 15)] = name

        # Teacher's Day
        if self.observed and date(year, SEP, 17):
            name = "Día del Maestro [Teacher's day] (Observed)"
            self[date(year, SEP, 17)] = name

        # October Holidays are joined on 3 days starting at October 3 to 6.
        # Some companies work medium day and take the rest on saturday.
        # This holiday is variant and some companies work normally.
        # If start day is weekend is ignored.
        # The main objective of this is to increase the tourism.

        # https://www.hondurastips.hn/2017/09/20/de-donde-nace-el-feriado-morazanico/

        if year <= 2014:
            # Morazan's Day
            if self.observed and date(year, OCT, 3):
                self[date(year, OCT, 3)] = "Día de Morazán [Morazan's Day]"

            # Columbus Day
            if self.observed and date(year, OCT, 12):
                self[date(year, OCT, 12)] = "Día de la Raza [Columbus Day]"

            # Amy Day
            if self.observed and date(year, OCT, 21):
                str_day = "Día de las Fuerzas Armadas [Army Day]"
                self[date(year, OCT, 21)] = str_day
        else:
            # Morazan Weekend
            if self.observed and date(year, OCT, 3):
                name = "Semana Morazánica [Morazan Weekend]"
                self[date(year, OCT, 3)] = name

            # Morazan Weekend
            if self.observed and date(year, OCT, 4):
                name = "Semana Morazánica [Morazan Weekend]"
                self[date(year, OCT, 4)] = name

            # Morazan Weekend
            if self.observed and date(year, OCT, 5):
                name = "Semana Morazánica [Morazan Weekend]"
                self[date(year, OCT, 5)] = name

        # Christmas
        self[date(year, DEC, 25)] = "Navidad [Christmas]"
Exemple #60
0
 def for_year(self, year):
     return [easter(year) + datetime.timedelta(days=self.days)]