Commit 16f8a2097fe6f6164877c47b8d0c50c9e3fdd49a

Authored by Imanol-Mikel Barba Sabariego
1 parent d5acea51

Removed useless code from 19

Showing 1 changed file with 5 additions and 50 deletions
... ... @@ -38,50 +38,6 @@ class Date:
38 38 def isLeap(year):
39 39 return (year % 4 == 0) and ((year % 100 != 0) or (year % 400 == 0))
40 40  
41   -def calcNumDays(start,end):
42   - days = 0
43   - currentMonth = start.month
44   - currentDay = start.day
45   - for year in range(start.year+1,end.year):
46   - if(isLeap(year)):
47   - days += 366
48   - else:
49   - days += 365
50   -
51   - leap = 0
52   - # Beginning
53   - year = start.year
54   - if(isLeap(year)):
55   - leap = 1
56   -
57   - for month in range(start.month+1, DEC+1):
58   - if(month in MONTHS_31):
59   - days += 31
60   - elif(month == FEB):
61   - days += 28
62   - else:
63   - days += 30
64   -
65   - days += (31 - start.day + 1 + leap)
66   -
67   - leap = 0
68   - # End
69   - year = end.year
70   - if(isLeap(year)):
71   - leap = 1
72   -
73   - for month in range(JAN,end.month):
74   - if(month in MONTHS_31):
75   - days += 31
76   - elif(month == FEB):
77   - days += 28
78   - else:
79   - days += 30
80   -
81   - days += (end.day + leap)
82   -
83   - return days
84   -
85 41 def getMonthLimit(month,year):
86 42 limit = 0
87 43 if(month in MONTHS_31):
... ... @@ -96,7 +52,7 @@ def getMonthLimit(month,year):
96 52  
97 53 return limit
98 54  
99   -def SundaysFirstOfMonth(start,initial,numDays):
  55 +def SundaysFirstOfMonth(start,end,initial):
100 56 sundays = 0
101 57 currentDay = start.day
102 58 currentMonth = start.month
... ... @@ -105,7 +61,9 @@ def SundaysFirstOfMonth(start,initial,numDays):
105 61  
106 62 limit = getMonthLimit(currentMonth, currentYear)
107 63  
108   - for i in range(0,numDays):
  64 + while True:
  65 + if(end.day == currentDay and end.month == currentMonth and end.year == currentYear):
  66 + return sundays
109 67 if (currentDay > limit):
110 68 currentMonth += 1
111 69 currentDay = 1
... ... @@ -120,15 +78,12 @@ def SundaysFirstOfMonth(start,initial,numDays):
120 78 currentDay += 1
121 79 currentWeekday = (currentWeekday + 1) % 7
122 80  
123   - return sundays
124   -
125 81 strDateEnd = sys.argv[1].split('/')
126 82  
127 83 dateStart = Date(1,1,1901)
128 84 dateEnd = Date(int(strDateEnd[0]),int(strDateEnd[1]),int(strDateEnd[2]))
129 85  
130 86 initialDay = TUE
131   -numDays = calcNumDays(dateStart,dateEnd)
132   -numSundays = SundaysFirstOfMonth(dateStart,initialDay,numDays)
  87 +numSundays = SundaysFirstOfMonth(dateStart,dateEnd,initialDay)
133 88  
134 89 print "Result is: " + str(numSundays)
... ...