<s> from __future__ import unicode_literals <EOL> from datetime import datetime <EOL> from django . template import defaultfilters <EOL> from django . utils . translation import ugettext as _ <EOL> from django . utils . timezone import is_aware , utc <EOL> from . registry import register <EOL> @ register . filter ( expects_localtime = True ) <EOL> def shortnaturaltime ( value ) : <EOL> """<STR_LIT>""" <EOL> tz = utc if is_aware ( value ) else None <EOL> now = datetime . now ( tz ) <EOL> if value > now : <EOL> return '<STR_LIT>' % { '<STR_LIT>' : defaultfilters . date ( value , '<STR_LIT>' ) } <EOL> delta = now - value <EOL> if delta . days : <EOL> if defaultfilters . date ( now , '<STR_LIT:y>' ) == defaultfilters . date ( value , '<STR_LIT:y>' ) : <EOL> return '<STR_LIT>' % { '<STR_LIT>' : defaultfilters . date ( value , '<STR_LIT>' ) } <EOL> return '<STR_LIT>' % { '<STR_LIT>' : defaultfilters . date ( value , '<STR_LIT>' ) } <EOL> if not delta . seconds : <EOL> return _ ( '<STR_LIT>' ) <EOL> count = delta . seconds <EOL> if count < <NUM_LIT> : <EOL> return _ ( '<STR_LIT>' ) % { '<STR_LIT:count>' : count } <EOL> count //= <NUM_LIT> <EOL> if count < <NUM_LIT> : <EOL> return _ ( '<STR_LIT>' ) % { '<STR_LIT:count>' : count } <EOL> count //= <NUM_LIT> <EOL> return _ ( '<STR_LIT>' ) % { '<STR_LIT:count>' : count } </s>
