-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|719|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
SoCoder -> Snippet Home -> Timing


 
HoboBen
Created : 26 March 2016
Edited : 26 March 2016
System : Cross Platform
Language : Python

naturaltime.py

human readable time deltas for Python

Given a Python datetime, generate a nice helpful string, relative to right now, like:

'tomorrow at 7:00 am'
'just now'
'about 42 minutes ago'



Gist

 

Comments


Saturday, 26 March 2016, 04:08
Jayenkai
Looks useful.
I'm surprised something like that isn't already part of the whole datetime thing. From the look of your code, datetime seems fairly comprehensive.
Sunday, 27 March 2016, 01:19
HoboBen
Datetimes in python, and in particular timedeltas, are super super handy

There is this module which can humanize all sorts of things for different languages, but it was overkill for me!

https://pypi.python.org/pypi/humanize