• Weekend Counter Problem

Question related to mission Weekend Counter

  I would like to give some feedback about ...  The problem just continues to load as if it is in an infinite loop.  My solution works appropriately in my IDE but hangs here.  It may be a problem with my code but it appears to work fine on my system.

From: http://www.checkio.org/mission/weekend-counter/solve/

HTTP\_USER\_AGENT:

    Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/35.0.1916.153 Safari/537.36

My Code:

    from datetime import date
    
    MonthsAndDays = {1:31,
                     2:28,
                     3:31,
                     4:30,
                     5:31,
                     6:30,
                     7:31,
                     8:31,
                     9:30,
                     10:31,
                     11:30,
                     12:31}
    
    def checkio(from_date, to_date):
        totalWeekends = 0
        fromDate = mydatetime()
        fromDate.month = from_date.month
        fromDate.day = from_date.day
        fromDate.year = from_date.year
    
        toDate = mydatetime()
        toDate.month = to_date.month
        toDate.day = to_date.day
        toDate.year = to_date.year
        if fromDate.day < toDate.day or fromDate.month < toDate.month or fromDate.year < toDate.year:
            while fromDate.createTuple() != toDate.createTuple():
                if fromDate.weekday() >= 5:
                    totalWeekends += 1
                if fromDate.day == MonthsAndDays[fromDate.month]:
                    fromDate.day = 0
                    fromDate.month += 1
                    if fromDate.month > 12:
                        fromDate.month = 1
    
                fromDate.day += 1
            if fromDate.weekday() >= 5:
                totalWeekends += 1
        return totalWeekends
    
    class mydatetime():
        day = 0
        month = 0
        year = 0
    
        def createTuple(self):
            return (self.day, self.month, self.year)
    
        def weekday(self):
            return date(self.year, self.month, self.day).weekday()
    
    #These "asserts" using only for self-checking and not necessary for auto-testing
    if __name__ == '__main__':
        assert checkio(date(2013, 9, 18), date(2013, 9, 23)) == 2, "1st example"
        assert checkio(date(2013, 1, 1), date(2013, 2, 1)) == 8, "2nd example"
        assert checkio(date(2013, 2, 2), date(2013, 2, 3)) == 2, "3rd example"