コード例 #1
0
    def _allocateLateChristmasSeason(self):
        '''
        Allocate the masses of the Christmas season that comes at the
        end of the year.
        '''

        self._appendMass(datetools.nextSunday(self.dateOfChristmas, -1),
                         'christmas/christmas-vigil')

        # Octave of Christmas
        self._appendMass(self.dateOfChristmas,
                         'christmas/christmas-at-midnight')
        self._appendMass(self.dateOfChristmas, 'christmas/christmas-at-dawn')
        self._appendMass(self.dateOfChristmas,
                         'christmas/christmas-during-the-day')

        massDates = datetools.inclusiveDateRange(
            self.dateOfChristmas + datetime.timedelta(days=1),
            datetime.date(self._year, 12, 31))
        massKeys = (
            'day-2-st-stephen',
            'day-3-st-john',
            'day-4-holy-innocents',
            'day-5',
            'day-6',
            'day-7',
        )
        for massDate, massKey in zip(massDates, massKeys):
            self._assignMass(
                massDate,
                getLectionary().findMass('christmas/%s' % massKey))

        dateOfHolyFamily = datetools.nextSunday(self.dateOfChristmas, 1)
        if dateOfHolyFamily.year == self._year:
            self._assignMass(dateOfHolyFamily, 'christmas/holy-family')
コード例 #2
0
    def dateOfEndOfPreviousChristmas(self):
        '''
        The date of the end of the Christmas Season from the previous
        year.
        '''

        if self.dateOfPreviousChristmas.weekday() == 6:
            return datetools.nextSunday(self.dateOfPreviousChristmas, +2)
        else:
            return datetools.nextSunday(self.dateOfPreviousChristmas, +3)
コード例 #3
0
    def _allocateEarlyChristmasSeason(self):
        '''
        Allocate the masses of the Christmas season that started in
        the previous year.
        '''

        # The Octave of Christmas.
        massDates = datetools.followingDays(self.dateOfPreviousChristmas, 6)
        massKeys = (
            'day-2-st-stephen',
            'day-3-st-john',
            'day-4-holy-innocents',
            'day-5',
            'day-6',
            'day-7',
        )
        for massDate, massKey in zip(massDates, massKeys):
            if massDate.year < self._year:
                continue
            self._assignMass(
                massDate,
                getLectionary().findmass('christmas/%s' % massKey))

        # Fixed-date weekday masses following Christmas.
        massDates = datetools.inclusiveDateRange(
            datetime.date(self._year, 1, 2), datetime.date(self._year, 1, 7))
        massKeys = ['christmas/01-%02d' % day for day in range(2, 8)]
        for massDate, massKey in zip(massDates, massKeys):
            self._assignMass(massDate, getLectionary().findMass(massKey))

        # The solemnity of Mary, Mother of God.
        self._assignMass(datetime.date(self._year, 1, 1), 'mary-mother-of-god')

        if self.dateOfPreviousChristmas.weekday() == 6:
            # Make adjustments for when Christmas falls on a Sunday.
            self._assignMass(self.dateOfEndOfPreviousChristmas,
                             'christmas/epiphany')
            self._assignMass(datetime.date(self._year, 1, 9),
                             'christmas/baptism-of-the-lord')
        else:
            self._assignMass(
                datetools.nextSunday(self.dateOfPreviousChristmas, +1),
                'christmas/holy-family')
            self._assignMass(
                datetools.nextSunday(self.dateOfPreviousChristmas, +2),
                'christmas/2nd-sunday-after-christmas')
            self._assignMass(datetime.date(self._year, 1, 6),
                             'christmas/epiphany')
            self._assignMass(self.dateOfEndOfPreviousChristmas,
                             'christmas/baptism-of-the-lord')
コード例 #4
0
 def test_badCount(self):
     with self.assertRaises(TypeError):
         datetools.nextSunday(datetime.date.today(), None)
     with self.assertRaises(TypeError):
         datetools.nextSunday(datetime.date.today(), '')
     with self.assertRaises(TypeError):
         datetools.nextSunday(datetime.date.today(), 0.0)
     with self.assertRaises(ValueError):
         datetools.nextSunday(datetime.date.today(), 0)
コード例 #5
0
 def test_badDate(self):
     with self.assertRaises(TypeError):
         datetools.nextSunday(None, 1)
     with self.assertRaises(TypeError):
         datetools.nextSunday('', 1)
     with self.assertRaises(TypeError):
         datetools.nextSunday(1, 1)
コード例 #6
0
    def _allocateLentenSeason(self):
        '''
        Allocate the masses of the Lenten season.
        '''

        # Week of Ash Wednesday
        massDates = [self.dateOfAshWednesday] + \
            datetools.followingDays(self.dateOfAshWednesday, 3)
        massKeys = (
            'ash-wednesday',
            'thursday',
            'friday',
            'saturday',
        )
        for massDate, massKey in zip(massDates, massKeys):
            self._assignMass(massDate,
                             'lent/week-of-ash-wednesday/%s' % massKey)

        sundayDates = (
            datetools.nextSunday(self.dateOfEaster, -6),
            datetools.nextSunday(self.dateOfEaster, -5),
            datetools.nextSunday(self.dateOfEaster, -4),
            datetools.nextSunday(self.dateOfEaster, -3),
            datetools.nextSunday(self.dateOfEaster, -2),
        )

        for sundayIndex, sundayDate in enumerate(sundayDates):
            # Assign the Sunday mass.
            self._assignMass(sundayDate,
                             'lent/week-%d/sunday' % (sundayIndex + 1))

            # Assign the weekday masses.
            for weekdayDate, weekdayMass in zip(
                    datetools.followingDays(sundayDate, 6),
                    getLectionary().weekdayMassesInWeek(
                        'lent', 'week-%d' % (sundayIndex + 1))):
                self._assignMass(weekdayDate, weekdayMass)
コード例 #7
0
    def _allocateAdventSeason(self):
        '''
        Allocate the masses of the Advent season.
        '''

        sundayDates = (
            self.dateOfFirstSundayOfAdvent,
            datetools.nextSunday(self.dateOfChristmas, -3),
            datetools.nextSunday(self.dateOfChristmas, -2),
            datetools.nextSunday(self.dateOfChristmas, -1),
        )
        for sundayIndex, sundayDate in enumerate(sundayDates):
            # Assign the Sunday mass.
            self._assignMass(sundayDate,
                             'advent/week-%d/sunday' % (sundayIndex + 1))

            # Assign the weekday masses.
            for weekdayDate, weekdayMass in zip(
                    datetools.followingDays(sundayDate, 6),
                    getLectionary().weekdayMassesInWeek(
                        'advent', 'week-%d' % (sundayIndex + 1))):
                self._assignMass(weekdayDate, weekdayMass)

        # Handle the fixed-date masses in Advent starting on December
        # 17th.  These override the other weekday masses of Advent,
        # but not the Sunday masses of Advent.
        massDates = datetools.inclusiveDateRange(
            datetime.date(self._year, 12, 17),
            datetime.date(self._year, 12, 24))
        massKeys = [
            'advent/end-of-advent/12-%02d' % day for day in range(17, 25)
        ]
        for massDate, massKey in zip(massDates, massKeys):
            if massDate.weekday() == 6:
                continue
            self._assignMass(massDate, massKey)
コード例 #8
0
    def _allocateHolyWeekAndEasterSeason(self):
        '''
        Allocate the masses of Holy Week and the Easter Season.
        '''

        # Holy Week
        dateOfPalmSunday = datetools.nextSunday(self.dateOfEaster, -1)
        self._assignMass(dateOfPalmSunday, 'holy-week/palm-sunday')

        massDates = datetools.followingDays(dateOfPalmSunday, 4)
        massKeys = ('monday', 'tuesday', 'wednesday', 'thursday-chrism-mass')
        for massDate, massKey in zip(massDates, massKeys):
            mass = getLectionary().findMass('holy-week/%s' % massKey)
            self._assignMass(massDate, mass)

        self._appendMass(self.dateOfEaster - datetime.timedelta(days=3),
                         'holy-week/mass-of-the-lords-supper')
        self._assignMass(self.dateOfEaster - datetime.timedelta(days=2),
                         'holy-week/good-friday')
        self._assignMass(self.dateOfEaster - datetime.timedelta(days=1),
                         'easter/easter-vigil')

        sundayDates = (
            self.dateOfEaster,
            datetools.nextSunday(self.dateOfEaster, 1),
            datetools.nextSunday(self.dateOfEaster, 2),
            datetools.nextSunday(self.dateOfEaster, 3),
            datetools.nextSunday(self.dateOfEaster, 4),
            datetools.nextSunday(self.dateOfEaster, 5),
            datetools.nextSunday(self.dateOfEaster, 6),
        )
        for sundayIndex, sundayDate in enumerate(sundayDates):
            # Assign the Sunday mass.
            if sundayIndex == 0:
                self._assignMass(sundayDate, 'easter/week-1/easter-sunday')
            else:
                self._assignMass(sundayDate,
                                 'easter/week-%d/sunday' % (sundayIndex + 1))

            # Assign the weekday masses.
            for weekdayDate, weekdayMass in zip(
                    datetools.followingDays(sundayDate, 6),
                    getLectionary().weekdayMassesInWeek(
                        'easter', 'week-%d' % (sundayIndex + 1))):
                self._assignMass(weekdayDate, weekdayMass)

        self._appendMass(self.dateOfPentecost - datetime.timedelta(days=1),
                         'easter/pentecost-vigil')
        self._assignMass(self.dateOfPentecost, 'easter/pentecost')
コード例 #9
0
    def test_dates(self):
        aSunday = datetime.date(2017, 9, 10)
        previousSunday1 = datetime.date(2017, 9, 3)
        previousSunday2 = datetime.date(2017, 8, 27)
        previousSunday3 = datetime.date(2017, 8, 20)
        nextSunday1 = datetime.date(2017, 9, 17)
        nextSunday2 = datetime.date(2017, 9, 24)
        nextSunday3 = datetime.date(2017, 10, 1)

        # A Sunday:
        self.assertEqual(previousSunday1, datetools.nextSunday(aSunday, -1))
        self.assertEqual(previousSunday2, datetools.nextSunday(aSunday, -2))
        self.assertEqual(previousSunday3, datetools.nextSunday(aSunday, -3))
        self.assertEqual(nextSunday1, datetools.nextSunday(aSunday, 1))
        self.assertEqual(nextSunday2, datetools.nextSunday(aSunday, 2))
        self.assertEqual(nextSunday3, datetools.nextSunday(aSunday, 3))

        # ...But not just any Monday.
        aMonday = datetime.date(2017, 9, 11)
        self.assertEqual(aSunday, datetools.nextSunday(aMonday, -1))
        self.assertEqual(previousSunday1, datetools.nextSunday(aMonday, -2))
        self.assertEqual(previousSunday2, datetools.nextSunday(aMonday, -3))
        self.assertEqual(nextSunday1, datetools.nextSunday(aMonday, 1))
        self.assertEqual(nextSunday2, datetools.nextSunday(aMonday, 2))
        self.assertEqual(nextSunday3, datetools.nextSunday(aMonday, 3))

        # A Saturday:
        aSaturday = datetime.date(2017, 9, 9)
        self.assertEqual(previousSunday1, datetools.nextSunday(aSaturday, -1))
        self.assertEqual(previousSunday2, datetools.nextSunday(aSaturday, -2))
        self.assertEqual(previousSunday3, datetools.nextSunday(aSaturday, -3))
        self.assertEqual(aSunday, datetools.nextSunday(aSaturday, 1))
        self.assertEqual(nextSunday1, datetools.nextSunday(aSaturday, 2))
        self.assertEqual(nextSunday2, datetools.nextSunday(aSaturday, 3))
コード例 #10
0
    def _allocateOrdinaryTime(self):
        '''
        Allocate the masses of Ordinary Time.
        '''

        # Ordinary Time Before Lent: Calculate and record the masses
        # of Ordinary Time that come between the end of Christmas and
        # Ash Wednesday.
        sundaysInOrdinaryTime = list(getLectionary().sundaysInOrdinaryTime)
        weekdaysInOrdinaryTime = [
            getLectionary().weekdayMassesInWeek('ordinary',
                                                'week-%d' % weekIndex)
            for weekIndex in range(1, 35)
        ]

        # Handle the weekday masses for the first week of ordinary
        # time as a special case.
        for weekdayDate, weekdayMass in zip(
                datetools.followingDays(self.dateOfEndOfPreviousChristmas, 6),
                weekdaysInOrdinaryTime.pop(0)):
            self._assignMass(weekdayDate, weekdayMass)

        sundayDate = datetools.nextSunday(self.dateOfEndOfPreviousChristmas,
                                          +1)
        while sundayDate < self.dateOfAshWednesday:
            # Assign the Sunday mass.
            try:
                self._assignMass(sundayDate, sundaysInOrdinaryTime.pop(0))
            except IndexError:
                print '***', sundayDate
                raise

            # Assign the weekday masses.
            for weekdayDate, weekdayMass in zip(
                    datetools.followingDays(sundayDate, 6),
                    weekdaysInOrdinaryTime.pop(0)):
                self._assignMass(weekdayDate, weekdayMass)

            sundayDate = datetools.nextSunday(sundayDate, +1)

        # Ordinary Time After Easter: Calculate and record the masses
        # of Ordinary Time that come between the end of Easter and
        # Advent.
        sundayDate = datetools.nextSunday(self.dateOfFirstSundayOfAdvent, -1)
        while sundayDate > datetools.nextSunday(self.dateOfPentecost, -1):
            # Assign the Sunday mass.
            self._assignMass(sundayDate, sundaysInOrdinaryTime.pop())

            # Assign the weekday masses.
            for weekdayDate, weekdayMass in zip(
                    datetools.followingDays(sundayDate, 6),
                    weekdaysInOrdinaryTime.pop()):
                self._assignMass(weekdayDate, weekdayMass)

            sundayDate = datetools.nextSunday(sundayDate, -1)

        # These special feasts in Ordinary Time have priority over
        # whatever else is being celebrated that day.
        self._assignMass(datetools.nextSunday(self.dateOfEaster, +8),
                         'trinity-sunday')

        corpusChristiDate = self.dateOfEaster + datetime.timedelta(days=60)
        if corpusChristiDate.weekday() in (5, 4, 3):
            corpusChristiDate += datetime.timedelta(
                days=6 - corpusChristiDate.weekday())
        self._assignMass(corpusChristiDate, 'corpus-christi')

        self._assignMass(self.dateOfEaster + datetime.timedelta(days=68),
                         'sacred-heart-of-jesus')
コード例 #11
0
    def dateOfFirstSundayOfAdvent(self):
        '''
        The date of the First Sunday of Advent
        '''

        return datetools.nextSunday(self.dateOfChristmas, -4)
コード例 #12
0
    def dateOfPentecost(self):
        '''
        The date of Pentecost Sunday
        '''

        return datetools.nextSunday(self.dateOfEaster, +7)