date/ の加算/減算をいじるための簡単なコードを取得しました。
def calculate(self, datemonthyear, add): #not handled the condition for years between 00 and 09.
year = datemonthyear % 100
datemonthyear = datemonthyear / 100
date = datemonthyear % 100
month = datemonthyear / 100
leapyear = (year % 4 == 0 or year==0)
print month
print date
print year
print ((leapyear and date + add > 29) or (not(leapyear) and date + add > 28))
if (month == 2 and ((leapyear and date + add > 29) or (not(leapyear) and date + add > 28))):
print "1"
return "301" + str(year)
elif month == 3 and leapyear and date + add < 1:
print "2"
return "229" + str(year)
elif month == 3 and not(leapyear) and date + add < 1:
print "3"
return "228" + str(year)
elif month in [1,3,5,7,8,10,12]:
print "4"
if month == 12 and date + add > 31:
return "101" + str((year + 1)%100)
elif month == 1 and date + add < 1:
return "1231" + str((year - 1)%100)
elif month == 8 and date + add < 1:
return "731" + str(year)
elif date + add > 31:
return str(month + 1) + "01" + str(year)
elif date + add < 1:
return str(month - 1) + "30" + str(year)
elif month in [2,4,6,9,11]:
print "5"
if date + add > 30:
return str(month + 1) + "01" + str(year)
elif date + add < 1:
return str (month -1) + "31" + str(year)
print "Has to come here"
return str(month) + str(date + add) + str(year)
私が電話するとき
print "22820 " + self.calculate(22820, 1)
このエラーがスローされます
E 120731 15:27:04 web:1064] Uncaught exception GET / (::1)
HTTPRequest(protocol='http', host='localhost:8881', method='GET', uri='/', version='HTTP/1.1', remote_ip='::1', body='', headers={'Accept-Language': 'en-US,en;q=0.8', 'Accept-Encoding': 'gzip,deflate,sdch', 'Host': 'localhost:8881', 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_4) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.151 Safari/535.19', 'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'Connection': 'keep-alive', 'Cookie': '_xsrf=2328f244ddf94402884f39490aeed347', 'Cache-Control': 'max-age=0'})
Traceback (most recent call last):
File "/Library/Python/2.7/site-packages/tornado-2.3-py2.7.egg/tornado/web.py", line 1021, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "trends.py", line 33, in get
print "22820 " + self.calculate(22820, 1)
TypeError: cannot concatenate 'str' and 'NoneType' objects
これは基本的に、計算が None を返すことを意味しますが、デバッグできません