<s> import datetime <EOL> import iso8601 <EOL> from django . template . defaultfilters import register <EOL> from django . template . defaultfilters import timesince <EOL> from django . utils . safestring import mark_safe <EOL> from django . utils import timezone <EOL> from django . utils . translation import ugettext_lazy as _ <EOL> @ register . filter <EOL> def replace_underscores ( string ) : <EOL> return string . replace ( "<STR_LIT:_>" , "<STR_LIT:U+0020>" ) <EOL> @ register . filter <EOL> def parse_isotime ( timestr , default = None ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> return iso8601 . parse_date ( timestr ) <EOL> except ( iso8601 . ParseError , TypeError ) : <EOL> return default or '<STR_LIT>' <EOL> @ register . filter <EOL> def timesince_or_never ( dt , default = None ) : <EOL> """<STR_LIT>""" <EOL> if default is None : <EOL> default = _ ( "<STR_LIT>" ) <EOL> if isinstance ( dt , datetime . date ) : <EOL> return timesince ( dt ) <EOL> else : <EOL> return default <EOL> @ register . filter <EOL> def timesince_sortable ( dt ) : <EOL> delta = timezone . now ( ) - dt <EOL> seconds = delta . seconds + ( delta . days * <NUM_LIT> * <NUM_LIT> ) <EOL> return mark_safe ( "<STR_LIT>" % <EOL> ( seconds , timesince ( dt ) ) ) </s>
