Python dateutil.rrule.YEARLY Examples

The following are 12 code examples of dateutil.rrule.YEARLY(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module dateutil.rrule , or try the search function .
Example #1
Source File: misc.py    From entsoe-py with MIT License 6 votes vote down vote up
def year_blocks(start, end):
    """
    Create pairs of start and end with max a year in between, to deal with usage restrictions on the API

    Parameters
    ----------
    start : dt.datetime | pd.Timestamp
    end : dt.datetime | pd.Timestamp

    Returns
    -------
    ((pd.Timestamp, pd.Timestamp))
    """
    rule = rrule.YEARLY

    res = []
    for day in rrule.rrule(rule, dtstart=start, until=end):
        res.append(pd.Timestamp(day))
    res.append(end)
    res = sorted(set(res))
    res = pairwise(res)
    return res 
Example #2
Source File: recurrence.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
def _getWhen(self, offset, numDays=1):
        retval = ""
        if self.freq == DAILY:
            retval = self.__getDailyWhen()

        elif self.freq == WEEKLY:
            retval = self.__getWeeklyWhen(offset)

        elif self.freq == MONTHLY:
            retval = self.__getMonthlyWhen(offset)

        elif self.freq == YEARLY:
            retval = self.__getYearlyWhen(offset)

        if numDays >= 2:
            retval += " "+_("for {n} days").format(n=numDays)
        if self.until:
            until = self.until + dt.timedelta(days=offset)
            retval += " "+_("(until {when})").format(when=dateShortFormat(until))
        return retval 
Example #3
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_year(self):
        """Repeat every year."""
        vrecurr = utils.build_rrule(freq="YEARLY")
        assert vrecurr["FREQ"] == "YEARLY"
        vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY"
        assert len(vrecurr.keys()) == 1 
Example #4
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_day_in_jan(self):
        """Repeat every day in January"""
        vrecurr = utils.build_rrule(
            freq="YEARLY", bymonth=1, byday=["MO", "TU", "WE", "TH", "FR", "SA", "SU"]
        )
        assert vrecurr["FREQ"] == "YEARLY"
        assert vrecurr["BYMONTH"] == 1
        assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR", "SA", "SU"]
        vRecur(
            vrecurr
        ).to_ical().decode() == "FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1"
        assert len(vrecurr.keys()) == 3 
Example #5
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_fr_13th(self):
        """Repeat every Friday the 13th."""
        vrecurr = utils.build_rrule(freq="YEARLY", bymonthday=13, byday="FR")
        assert vrecurr["FREQ"] == "YEARLY"
        assert vrecurr["BYMONTHDAY"] == 13
        assert vrecurr["BYDAY"] == "FR"
        vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY;BYDAY=FR;BYMONTHDAY=13"
        assert len(vrecurr.keys()) == 3 
Example #6
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_year(self):
        """Repeat every year."""
        vrecurr = utils.build_rrule_from_text("FREQ=YEARLY")
        assert vrecurr["FREQ"] == ["YEARLY"]
        vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY"
        assert len(vrecurr.keys()) == 1 
Example #7
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_every_day_in_jan(self):
        """Repeat every day in January"""
        vrecurr = utils.build_rrule_from_text(
            "FREQ=YEARLY;BYMONTH=1;BYDAY=MO,TU,WE,TH,FR,SA,SU;"
        )
        assert vrecurr["FREQ"] == ["YEARLY"]
        assert vrecurr["BYMONTH"] == [1]
        assert vrecurr["BYDAY"] == ["MO", "TU", "WE", "TH", "FR", "SA", "SU"]
        vRecur(
            vrecurr
        ).to_ical().decode() == "FREQ=YEARLY;BYDAY=MO,TU,WE,TH,FR,SA,SU;BYMONTH=1"
        assert len(vrecurr.keys()) == 3 
Example #8
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_yearly_month_nweekday(self):
        rule = rrule(
            YEARLY,
            count=3,
            bymonth=(1, 3),
            byweekday=(TU(1), TH(-1)),
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        vRecur(
            vrecurr
        ).to_ical().decode() == "FREQ=YEARLY;COUNT=3;BYDAY=+1TU,-1TH;BYMONTH=1,3" 
Example #9
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_yearly_month_yearday(self):
        rule = rrule(
            YEARLY,
            count=4,
            bymonth=(4, 7),
            byyearday=(1, 100, 200, 365),
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        assert (
            vRecur(vrecurr).to_ical().decode()
            == "FREQ=YEARLY;COUNT=4;BYYEARDAY=1,100,200,365;BYMONTH=4,7"
        ) 
Example #10
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_yearly_weekno_weekday(self):
        rule = rrule(
            YEARLY,
            count=3,
            byweekno=1,
            byweekday=MO,
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        vRecur(vrecurr).to_ical().decode() == "FREQ=YEARLY;COUNT=3;BYDAY=MO;BYWEEKNO=1" 
Example #11
Source File: test_recurrence.py    From django-ical with MIT License 5 votes vote down vote up
def test_yearly_setpos(self):
        rule = rrule(
            YEARLY,
            count=3,
            bymonthday=15,
            byhour=(6, 18),
            bysetpos=(3, -3),
            dtstart=datetime.datetime(1997, 9, 2, 9, 0),
        )
        vrecurr = utils.build_rrule_from_dateutil_rrule(rule)
        assert (
            vRecur(vrecurr).to_ical().decode()
            == "FREQ=YEARLY;COUNT=3;BYHOUR=6,18;BYMONTHDAY=15;BYSETPOS=3,-3"
        ) 
Example #12
Source File: recurrence.py    From ls.joyous with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def frequency(self):
        """
        How often the recurrence repeats.
        ("YEARLY", "MONTHLY", "WEEKLY", "DAILY")
        """
        freqOptions = ("YEARLY", "MONTHLY", "WEEKLY", "DAILY")
        if self.rule._freq < len(freqOptions):
            return freqOptions[self.rule._freq]
        else:
            return "unsupported_frequency_{}".format(self.rule._freq)