Ticket #4768: dateformat_timesince_cleanup.diff

File dateformat_timesince_cleanup.diff, 1.5 KB (added by John Shaffer <jshaffer2112@…>, 17 years ago)

Use explicit int division and remove the millisecond code.

  • django/utils/timesince.py

     
    3333    delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
    3434    since = delta.days * 24 * 60 * 60 + delta.seconds
    3535    for i, (seconds, name) in enumerate(chunks):
    36         count = since / seconds
     36        count = since // seconds
    3737        if count != 0:
    3838            break
    39     if count < 0:
    40         return ugettext('%d milliseconds') % math.floor((now - d).microseconds / 1000)
    4139    s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)}
    4240    if i + 1 < len(chunks):
    4341        # Now get the second item
    4442        seconds2, name2 = chunks[i + 1]
    45         count2 = (since - (seconds * count)) / seconds2
     43        count2 = (since - (seconds * count)) // seconds2
    4644        if count2 != 0:
    4745            s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)}
    4846    return s
  • django/utils/dateformat.py

     
    227227                week_number = 1
    228228            else:
    229229                j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
    230                 week_number = j / 7
     230                week_number = j // 7
    231231                if jan1_weekday > 4:
    232232                    week_number -= 1
    233233        return week_number
Back to Top