Ticket #2675: timesince.diff
File timesince.diff, 2.4 KB (added by , 17 years ago) |
---|
-
django/utils/timesince.py
32 32 # ignore microsecond part of 'd' since we removed it from 'now' 33 33 delta = now - (d - datetime.timedelta(0, 0, d.microsecond)) 34 34 since = delta.days * 24 * 60 * 60 + delta.seconds 35 for i, (seconds, name) in enumerate(chunks): 36 count = since // seconds 37 if count != 0: 38 break 39 s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)} 40 if i + 1 < len(chunks): 41 # Now get the second item 42 seconds2, name2 = chunks[i + 1] 43 count2 = (since - (seconds * count)) // seconds2 44 if count2 != 0: 45 s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)} 35 if since < 0: 36 s = u'0 ' + ugettext('minutes') 37 else: 38 for i, (seconds, name) in enumerate(chunks): 39 count = since // seconds 40 if count != 0: 41 break 42 s = ugettext('%(number)d %(type)s') % {'number': count, 'type': name(count)} 43 if i + 1 < len(chunks): 44 # Now get the second item 45 seconds2, name2 = chunks[i + 1] 46 count2 = (since - (seconds * count)) // seconds2 47 if count2 != 0: 48 s += ugettext(', %(number)d %(type)s') % {'number': count2, 'type': name2(count2)} 46 49 return s 47 50 48 51 def timeuntil(d, now=None): -
docs/templates.txt
1272 1272 June 2006, and ``comment_date`` is a date instance for 08:00 on 1 June 2006, 1273 1273 then ``{{ comment_date|timesince:blog_date }}`` would return "8 hours". 1274 1274 1275 If the time interval is small enough, it will be expressed in minutes. 1276 "0 minutes" will be returned for any date that is in the future relative 1277 to the comparison point. 1278 1275 1279 timeuntil 1276 1280 ~~~~~~~~~ 1277 1281 … … 1284 1288 the comparison point (instead of *now*). If ``from_date`` contains 22 June 1285 1289 2006, then ``{{ conference_date|timeuntil:from_date }}`` will return "7 days". 1286 1290 1291 If the time interval is small enough, it will be expressed in minutes. 1292 "0 minutes" will be returned for any date that is in the past relative to 1293 the comparison point. 1294 1287 1295 title 1288 1296 ~~~~~ 1289 1297