Created
May 24, 2014 04:36
-
-
Save helpse/87f6a4167df4b97f9dc1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
def prettydate(d): | |
diff = datetime.datetime.utcnow() - d | |
s = diff.seconds | |
if diff.days > 7 or diff.days < 0: | |
return d.strftime('%d %b %y') | |
elif diff.days == 1: | |
return '1 day ago' | |
elif diff.days > 1: | |
return '{} days ago'.format(diff.days) | |
elif s <= 1: | |
return 'just now' | |
elif s < 60: | |
return '{} seconds ago'.format(s) | |
elif s < 120: | |
return '1 minute ago' | |
elif s < 3600: | |
return '{} minutes ago'.format(s/60) | |
elif s < 7200: | |
return '1 hour ago' | |
else: | |
return '{} hours ago'.format(s/3600) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment