#14157: Birthday calculation failing silently
------------------------------------+---------------------------------------
          Reporter:  nil_von_9wo    |         Owner:  nobody
            Status:  closed         |     Milestone:        
         Component:  Uncategorized  |       Version:  1.2   
        Resolution:  invalid        |      Keywords:        
             Stage:  Unreviewed     |     Has_patch:  0     
        Needs_docs:  0              |   Needs_tests:  0     
Needs_better_patch:  0              |  
------------------------------------+---------------------------------------
Changes (by ramiro):

  * status:  new => closed
  * resolution:  => invalid

Comment:

 You are declaring the `today` var as a `datetime` and are trying to
 compare it with a `date` value (`born`, obtained from the Django
 `DateField`).

 {{{
 #!python
 >>> import datetime
 >>> born =  datetime.date(1971, 11, 26)
 >>> today = datetime.date.today()
 >>> try:
 ...     bday = born.replace(year=today.year)
 ... except ValueError:
 ...     bday = born.replace(year=today.year, day=born.day-1)
 ...
 >>> bday
 datetime.date(2010, 11, 26)
 >>> bday > today
 True
 >>> wrong_today = datetime.datetime.today()
 >>> bday > wrong_today
 Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
 TypeError: can't compare datetime.datetime to datetime.date
 }}}

 Please review your code because I doubt it is working on the command line
 in its current form.

 Closing ticket as invalid because it's a basic Python problem.

-- 
Ticket URL: <http://code.djangoproject.com/ticket/14157#comment:2>
Django <http://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to