Fixed #4768 -- Converted timesince and dateformat to use explicit floor division (pre-emptive avoidance of Python 3000 compatibility problem), and removed a redundant millisecond check. Thanks, John Shaffer <jshaffer2112@gmail.com>.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@5671 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Russell Keith-Magee 2007-07-12 13:55:19 +00:00
parent 1345f3c521
commit 34655a3e78
3 changed files with 4 additions and 5 deletions

View File

@ -225,6 +225,7 @@ answer newbie questions, and generally made Django that much better:
David Schein David Schein
scott@staplefish.com scott@staplefish.com
serbaut@gmail.com serbaut@gmail.com
John Shaffer <jshaffer2112@gmail.com>
Pete Shinners <pete@shinners.org> Pete Shinners <pete@shinners.org>
Jozko Skrablin <jozko.skrablin@gmail.com> Jozko Skrablin <jozko.skrablin@gmail.com>
SmileyChris <smileychris@gmail.com> SmileyChris <smileychris@gmail.com>

View File

@ -227,7 +227,7 @@ class DateFormat(TimeFormat):
week_number = 1 week_number = 1
else: else:
j = day_of_year + (7 - weekday) + (jan1_weekday - 1) j = day_of_year + (7 - weekday) + (jan1_weekday - 1)
week_number = j / 7 week_number = j // 7
if jan1_weekday > 4: if jan1_weekday > 4:
week_number -= 1 week_number -= 1
return week_number return week_number

View File

@ -33,16 +33,14 @@ def timesince(d, now=None):
delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
since = delta.days * 24 * 60 * 60 + delta.seconds since = delta.days * 24 * 60 * 60 + delta.seconds
for i, (seconds, name) in enumerate(chunks): for i, (seconds, name) in enumerate(chunks):
count = since / seconds count = since // seconds
if count != 0: if count != 0:
break break
if count < 0:
return ugettext('%d milliseconds') % math.floor((now - d).microseconds / 1000)
s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)} s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)}
if i + 1 < len(chunks): if i + 1 < len(chunks):
# Now get the second item # Now get the second item
seconds2, name2 = chunks[i + 1] seconds2, name2 = chunks[i + 1]
count2 = (since - (seconds * count)) / seconds2 count2 = (since - (seconds * count)) // seconds2
if count2 != 0: if count2 != 0:
s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)} s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)}
return s return s