diff options
author | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-04-08 14:46:38 +0200 |
---|---|---|
committer | Sylvain Th?nault <sylvain.thenault@logilab.fr> | 2011-04-08 14:46:38 +0200 |
commit | 361ca31f9f45b844cdeb4032adb39927147cd33b (patch) | |
tree | 6037516c5f685eca896b281492eed9ce5c5a5ff0 | |
parent | 2a59f072924490ef116fc301fc152f09ad466fc4 (diff) | |
download | logilab-common-361ca31f9f45b844cdeb4032adb39927147cd33b.tar.gz |
new datetime/delta <-> seconds/days conversion function
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | date.py | 14 |
2 files changed, 18 insertions, 0 deletions
@@ -1,5 +1,9 @@ ChangeLog for logilab.common ============================ + + -- +* date: new datetime/delta <-> seconds/days conversion function + 2011-04-01 -- 0.55.2 * new function for password generation in shellutils @@ -16,6 +16,7 @@ # You should have received a copy of the GNU Lesser General Public License along # with logilab-common. If not, see <http://www.gnu.org/licenses/>. """Date manipulation helper functions.""" +from __future__ import division __docformat__ = "restructuredtext en" @@ -307,3 +308,16 @@ def utcdatetime(dt): def utctime(dt): return (dt + dt.utcoffset() + dt.dst()).replace(tzinfo=None) + +def datetime_to_seconds(date): + """return the number of seconds since the begining of the day for that date + """ + return date.second+60*date.minute + 3600*date.hour + +def timedelta_to_days(delta): + """return the time delta as a number of seconds""" + return delta.days + delta.seconds / (3600*24) + +def timedelta_to_seconds(delta): + """return the time delta as a fraction of days""" + return delta.days*(3600*24) + delta.seconds |