Skip to content

Instantly share code, notes, and snippets.

(*
Copyright (c) 2013, Richard Emile Sarkis <[email protected]>
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
@glyphobet
glyphobet / elapsed_time.py
Created June 3, 2012 10:46 — forked from mwhooker/elapsed_time.py
humanize elapsed time
def elapsed_time(start, end):
"""
>>> from datetime import datetime
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 1, 20, 15))
'20 hours, and 15 minutes'
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 1, 0, 1))
'1 minute'
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 2, 0, 1))
'1 day, and 1 minute'
>>> elapsed_time(datetime(2000, 1, 1), datetime(2000, 1, 2, 2, 3, 4))