view content/Python/timedelta.md @ 27:04a8afe79c59

swith to anydns.info
author Dirk Olmes <dirk@xanthippe.ping.de>
date Tue, 08 Apr 2014 12:03:13 +0200
parents 4cd9b65e10e4
children 7380bf280fc9
line wrap: on
line source

Title: timedelta
Date: 2009-01-10
Lang: en

Python comes with a rich libray of classes for dealing with date and time. I was working with datetime.time objects the other day and needed to calculate the difference between to time instances. To my great surprise this isn't easily doable as Python's standard lib only has `timedelta` objects which cannot deal with pure time objects.

So I had to write my own [timedelta](http://xanthippe.anydns.info/cgi-bin/hgwebdir.cgi/timedelta/shortlog/tip) function which takes two time instances and calculates the difference. The diff will be returned as a time instance.

The source is [publicly available from its mercurial repository](http://xanthippe.anydns.info/hg/timedelta/shortlog/tip).