<s> from __future__ import unicode_literals <EOL> import datetime <EOL> from django . utils . html import avoid_wrapping <EOL> from django . utils . timezone import is_aware , utc <EOL> from django . utils . translation import ugettext , ungettext_lazy <EOL> def timesince ( d , now = None , reversed = False ) : <EOL> """<STR_LIT>""" <EOL> chunks = ( <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:30> , ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> * <NUM_LIT:7> , ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> * <NUM_LIT> , ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> * <NUM_LIT> , ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' ) ) , <EOL> ( <NUM_LIT> , ungettext_lazy ( '<STR_LIT>' , '<STR_LIT>' ) ) <EOL> ) <EOL> if not isinstance ( d , datetime . datetime ) : <EOL> d = datetime . datetime ( d . year , d . month , d . day ) <EOL> if now and not isinstance ( now , datetime . datetime ) : <EOL> now = datetime . datetime ( now . year , now . month , now . day ) <EOL> if not now : <EOL> now = datetime . datetime . now ( utc if is_aware ( d ) else None ) <EOL> delta = ( d - now ) if reversed else ( now - d ) <EOL> since = delta . days * <NUM_LIT> * <NUM_LIT> * <NUM_LIT> + delta . seconds <EOL> if since <= <NUM_LIT:0> : <EOL> return avoid_wrapping ( ugettext ( '<STR_LIT>' ) ) <EOL> for i , ( seconds , name ) in enumerate ( chunks ) : <EOL> count = since // seconds <EOL> if count != <NUM_LIT:0> : <EOL> break <EOL> result = avoid_wrapping ( name % count ) <EOL> if i + <NUM_LIT:1> < len ( chunks ) : <EOL> seconds2 , name2 = chunks [ i + <NUM_LIT:1> ] <EOL> count2 = ( since - ( seconds * count ) ) // seconds2 <EOL> if count2 != <NUM_LIT:0> : <EOL> result += ugettext ( '<STR_LIT:U+002CU+0020>' ) + avoid_wrapping ( name2 % count2 ) <EOL> return result <EOL> def timeuntil ( d , now = None ) : <EOL> """<STR_LIT>""" <EOL> return timesince ( d , now , reversed = True ) </s>
