[PhotoFloat] [PATCH] Fix type error in date comparison

Aleksandar Dimitrov aleks.dimitrov at gmail.com
Sun Jan 26 20:19:54 CET 2014


Hi list,

I'm a new PhotoFloat user. I got bitten by that type error in the comparison
between date.datetime and unicode. I've scratched my own itch. The patch below
works for me.

Thanks,
Aleks

Aleksandar Dimitrov (1):
  Fix type error in date comparison.

 scanner/PhotoAlbum.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

-- 
1.8.4.rc3

From ff07c7f522d539f8ea1006587a9f5186ea93ad95 Mon Sep 17 00:00:00 2001
From: Aleksandar Dimitrov <aleks.dimitrov at gmail.com>
Date: Sun, 26 Jan 2014 20:00:50 +0100
Subject: [PATCH] Fix type error in date comparison.

To be fair, this is a superficial fix. I didn't go spelunking into the rest of
the code base and just assumed it'd be beneficial to actually use dates (not
unicode string values) for the comparision of a variable named date_compare.

If that's not appropriate, there might be some subtle things going wrong.
---
 scanner/PhotoAlbum.py | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/scanner/PhotoAlbum.py b/scanner/PhotoAlbum.py
index aeb3087..27410b3 100644
--- a/scanner/PhotoAlbum.py
+++ b/scanner/PhotoAlbum.py
@@ -314,8 +314,16 @@ class Photo(object):
 			return self._attributes["dateTime"]
 		else:
 			return self._attributes["dateTimeFile"]
+	@staticmethod
+	def parsedate(stringordate):
+		if type(stringordate) is unicode:
+			date_format = "%Y:%m:%d %H:%M:%S"
+			return datetime.strptime(stringordate,date_format)
+		else:
+			return stringordate
 	def __cmp__(self, other):
-		date_compare = cmp(self.date, other.date)
+		date_compare = cmp(Photo.parsedate(self.date),
+		                   Photo.parsedate(other.date))
 		if date_compare == 0:
 			return cmp(self.name, other.name)
 		return date_compare
-- 
1.8.4.rc3

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.zx2c4.com/pipermail/photofloat/attachments/20140126/8ec3050f/attachment.asc>


More information about the PhotoFloat mailing list