Patchwork Don't use total_seconds for python < 2.7

login
register
mail settings
Submitter Konstantin Ryabitsev
Date June 13, 2013, 2:50 p.m.
Message ID <1371135056-6465-1-git-send-email-mricon@kernel.org>
Download mbox | patch
Permalink /patch/251091/
State Accepted
Headers show

Comments

Konstantin Ryabitsev - June 13, 2013, 2:50 p.m.
The total_seconds function was added to datetime in python-2.7. For
compatibility with previous versions of python, use its suggested
equivalent (except drop microseconds, since we don't care about them in
this context).

Signed-off-by: Konstantin Ryabitsev <mricon@kernel.org>
---
 apps/patchwork/views/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Jeremy Kerr - June 27, 2013, 1:16 p.m.
Hi Konstantin,

> The total_seconds function was added to datetime in python-2.7. For
> compatibility with previous versions of python, use its suggested
> equivalent (except drop microseconds, since we don't care about them in
> this context).

Thanks for that - applied.

Cheers,


Jeremy

Patch

diff --git a/apps/patchwork/views/__init__.py b/apps/patchwork/views/__init__.py
index 681532a..a823388 100644
--- a/apps/patchwork/views/__init__.py
+++ b/apps/patchwork/views/__init__.py
@@ -190,8 +190,8 @@  def patch_to_mbox(patch):
     if patch.content:
         body += '\n' + patch.content
 
-    utc_timestamp = (patch.date -
-            datetime.datetime.utcfromtimestamp(0)).total_seconds()
+    delta = patch.date - datetime.datetime.utcfromtimestamp(0)
+    utc_timestamp = delta.seconds + delta.days*24*3600
 
     mail = PatchMbox(body)
     mail['Subject'] = patch.name