Package npsgd :: Module text_helpers
[hide private]
[frames] | no frames]

Source Code for Module npsgd.text_helpers

 1  # Author: Thomas Dimson [tdimson@gmail.com] 
 2  # Date:   January 2011 
 3  # For distribution details, see LICENSE 
 4  """Module containing any functions that are useful for templates.""" 
 5   
6 -def pretty_forward_time_delta(diff):
7 day_diff = diff.days 8 second_diff = diff.seconds 9 10 if day_diff < 0: 11 return '' 12 13 if day_diff == 0: 14 if second_diff < 10: 15 return "just now" 16 if second_diff < 60: 17 return str(second_diff) + " seconds" 18 if second_diff < 120: 19 return "a minute" 20 if second_diff < 3600: 21 return str( second_diff / 60 ) + " minutes" 22 if second_diff < 7200: 23 return "an hour ago" 24 if second_diff < 86400: 25 return str( second_diff / 3600 ) + " hours" 26 27 if day_diff == 1: 28 return "a day" 29 if day_diff < 7: 30 return str(day_diff) + " days" 31 if day_diff < 31: 32 return str(day_diff/7) + " weeks" 33 if day_diff < 365: 34 return str(day_diff/30) + " months" 35 return str(day_diff/365) + " years"
36