summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Th?nault <sylvain.thenault@logilab.fr>2011-04-08 14:46:38 +0200
committerSylvain Th?nault <sylvain.thenault@logilab.fr>2011-04-08 14:46:38 +0200
commit361ca31f9f45b844cdeb4032adb39927147cd33b (patch)
tree6037516c5f685eca896b281492eed9ce5c5a5ff0
parent2a59f072924490ef116fc301fc152f09ad466fc4 (diff)
downloadlogilab-common-361ca31f9f45b844cdeb4032adb39927147cd33b.tar.gz
new datetime/delta <-> seconds/days conversion function
-rw-r--r--ChangeLog4
-rw-r--r--date.py14
2 files changed, 18 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 985f00a..c3044f4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/date.py b/date.py
index b52e5fe..0dbbf51 100644
--- a/date.py
+++ b/date.py
@@ -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