+def my_diff_time(timestamp):
+ now = time.time()
+ if timestamp == None:
+ return "not yet contacted"
+ diff = now - timestamp
+ # return the number of seconds as a difference from current time.
+ t_str = ""
+ if diff < 60: # sec in min.
+ t = diff
+ t_str = "%s sec ago" % t
+ elif diff < 60*60: # sec in hour
+ t = diff // (60)
+ t_str = "%s min ago" % int(t)
+ elif diff < 60*60*24: # sec in day
+ t = diff // (60*60)
+ t_str = "%s hours ago" % int(t)
+ elif diff < 60*60*24*7: # sec in week
+ t = diff // (60*60*24)
+ t_str = "%s days ago" % int(t)
+ elif diff < 60*60*24*30: # approx sec in month
+ t = diff // (60*60*24*7)
+ t_str = "%s weeks ago" % int(t)
+ elif diff > 60*60*24*30 and diff < 60*60*24*30*2: # approx sec in month
+ month = int( diff // (60*60*24*30) )
+ weeks = (diff - (month * (60*60*24*30))) // (60*60*24*7)
+ if weeks == 0:
+ t_str = "%s month ago" % int(month)
+ elif weeks == 4:
+ t_str = "2 months ago"
+ else:
+ t_str = "%s month and %s weeks ago" % ( int(month) , int(weeks) )
+ elif diff >= 60*60*24*30*2:
+ month = diff // (60*60*24*30)
+ t_str = "%s months ago" % int(month)
+ return t_str