def test_bday(self):
     """
     bday turns any date into a date in a specific year, 
     for comparison of month and day
     """
     self.assertEqual(helpers.bday(4, 14), date(helpers.NORMALIZED_YEAR, 4, 14))
     self.assertEqual(helpers.bday(now=True), date(helpers.NORMALIZED_YEAR, now().month, now().day))
 def filter_birthday_in(cls, days, skip=1):
     """
     Get list of all people with birthday in the next X days.
     By default it skips 1 day to start search tomorrow.
     Can be altered with skip=N.
     """
     future_date = (now() + datetime.timedelta(days=days)).date()
     start = (now() + datetime.timedelta(days=skip)).date()
     return h.filter_date_range(
             cls.objects,
             'birthday',
             h.bday(start.month, start.day),
             h.bday(future_date.month, future_date.day)
         )
 def queryset(self, request, queryset):
     # select by date... Patient.objects.filter(birthday__month=4, birthday__day=1)
     if self.value() == 'today':
         return queryset.filter(
                 birthday = h.bday(now=True)
             )
     if self.value() == 'week':
         future_date = (now() + datetime.timedelta(days=7)).date()
         return h.filter_date_range(
                 queryset,
                 'birthday',
                 h.bday(now=True),
                 h.bday(future_date.month, future_date.day)
             )
 def test_birthday_setting(self):
     """
     Every person should have created birthday entry from birthdate
     automaticaly.
     """
     g.create_volunteers(1)
     v = Volunteer.objects.get(id=1)
     self.assertEqual(
             v.birthday,
             helpers.bday(v.birthdate.month, v.birthdate.day))
    def test_birthday_filter(self):
        """
        Verify if we correctly gets list of people with birthdays in next X days.
        """
        today = now().date()
        normalized = helpers.bday(today.month, today.day)
        tomorrow = normalized + datetime.timedelta(days=1)
        next_week = normalized + datetime.timedelta(days=8)
        for i in range (-5,10):
            v = Volunteer(
                    surname="bd-filter-%d" % i,
                    birthdate = today + datetime.timedelta(days=i))
            v.save()

        # today
        for v in Volunteer.filter_birthday_in(days=0, skip=0):
            self.assertTrue(v.birthday_today())
        # next 7 days
        for v in Volunteer.filter_birthday_in(7):
            self.assertTrue( tomorrow <= v.birthday <= next_week )
 def save(self, *args, **kwargs):
     self.birthday = h.bday(self.birthdate.month, self.birthdate.day)
     super(Person, self).save(*args, **kwargs)
 def birthday_today(self):
     return self.birthday == h.bday(now=True)