[issue9909] request for calendar.dayofyear() function

Abhay Saxena report at bugs.python.org
Sat Nov 20 22:07:02 CET 2010


Abhay Saxena <ark3 at email.com> added the comment:

Quick hack alternative test. It would look nicer if the test used the datetime module, but I'm not sure that would be appropriate.


    def test_dayofyear(self):                                                                                                  
        """Test for the calendar.dayofyear() function, which computes the                                                      
        integer between 1 and 366 (inclusive) representing the specified day in                                                
        the specified month of the specified year.                                                                             
                                                                                                                               
        """                                                                                                                    
        for expected_total, year in (366, 2008), (365, 2010):                                                                  
            expected_day_of_year = 1                                                                                           
            for month in range(1, 13):                                                                                         
                lastDay = calendar.mdays[month]                                                                                
                if year == 2008 and month == 2:                                                                                
                    lastDay = 29                                                                                               
                for day in range(1, lastDay + 1):                                                                              
                    day_of_year = calendar.dayofyear(year, month, day)                                                         
                    self.assertEqual(expected_day_of_year, day_of_year)                                                        
                    # The computed day of the year must be between 1 and 366.                                                  
                    self.assertGreaterEqual(day_of_year, 1)                                                                    
                    self.assertLessEqual(day_of_year, 366)                                                                     
                    expected_day_of_year += 1                                                                                  
            self.assertEqual(expected_day_of_year - 1, expected_total)

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9909>
_______________________________________


More information about the Python-bugs-list mailing list