Fix cc date validation error

This check was raising a value error if run on the 31st against an expiration
date in a month that only had 30 days. Now we pick the 1st day of the month,
which is guaranteed to exist.

Also uses the correct timezone.
This commit is contained in:
shlurbee
2012-07-31 15:36:43 -07:00
parent 0aa9967d82
commit 47a6a88ca0

View File

@@ -1665,14 +1665,14 @@ class ValidCard(Validator):
self.set_error(_("dates should be YYYY-MM"), "expirationDate")
has_errors = True
else:
now = datetime.now()
now = datetime.now(g.tz)
yyyy, mm = expirationDate.split("-")
year = int(yyyy)
month = int(mm)
if month < 1 or month > 12:
self.set_error(_("month must be in the range 01..12"), "expirationDate")
has_errors = True
elif datetime(year, month, now.day) < now:
elif datetime(year, month, 1) < datetime(now.year, now.month, 1):
self.set_error(_("expiration date must be in the future"), "expirationDate")
has_errors = True