Skip to content

Commit

Permalink
Fix cc date validation error
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
shlurbee committed Aug 1, 2012
1 parent 0aa9967 commit 47a6a88
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions r2/r2/controllers/validator/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,14 +1665,14 @@ def run(self, cardNumber, expirationDate, cardCode):
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

Expand Down

0 comments on commit 47a6a88

Please sign in to comment.