#NEWLINE# @ register . filter #NEWLINE# def gmail_time( dtime , now = None ) : #NEWLINE# #INDENT# if ( dtime . tzinfo is None ) : #NEWLINE# #INDENT# dtime = dtime . replace ( tzinfo = pytz . utc ) #NEWLINE# user_time_zone = pytz . timezone ( getattr ( settings , 'USER_TIME_ZONE' , 'GMT' ) ) #NEWLINE# dtime = dtime . astimezone ( user_time_zone ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# dtime = dtime . astimezone ( timezone . get_current_timezone ( ) ) #NEWLINE# #UNINDENT# if ( not now ) : #NEWLINE# #INDENT# now = timezone . now ( ) #NEWLINE# #UNINDENT# if ( now . tzinfo is None ) : #NEWLINE# #INDENT# now = now . replace ( tzinfo = pytz . utc ) #NEWLINE# #UNINDENT# twelve_hours_ago = ( now - timedelta ( hours = 12 ) ) #NEWLINE# if ( dtime > twelve_hours_ago ) : #NEWLINE# #INDENT# return ( '%d:%s %s' % ( int ( dtime . strftime ( '%I' ) ) , dtime . strftime ( '%M' ) , dtime . strftime ( '%p' ) . lower ( ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( now . year == dtime . year ) : #NEWLINE# #INDENT# return ( '%s %d' % ( dtime . strftime ( '%b' ) , int ( dtime . strftime ( '%d' ) ) ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( '%d/%d/%s' % ( int ( dtime . strftime ( '%d' ) ) , int ( dtime . strftime ( '%m' ) ) , dtime . strftime ( '%y' ) ) )