Applying patch from iXce to fix an issue with time when the user's locale didn't...
authorEd Page <eopage@byu.net>
Sat, 6 Mar 2010 00:01:24 +0000 (18:01 -0600)
committerEd Page <eopage@byu.net>
Sat, 6 Mar 2010 00:01:24 +0000 (18:01 -0600)
src/backends/gvoice.py

index e9dff98..5952853 100755 (executable)
@@ -557,7 +557,7 @@ class GVoiceBackend(object):
                for messageId, messageHtml in itergroup(splitVoicemail[1:], 2):
                        exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
                        exactTime = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
-                       exactTime = datetime.datetime.strptime(exactTime, "%m/%d/%y %I:%M %p")
+                       exactTime = google_strptime(exactTime)
                        relativeTimeGroup = self._relativeVoicemailTimeRegex.search(messageHtml)
                        relativeTime = relativeTimeGroup.group(1).strip() if relativeTimeGroup else ""
                        locationGroup = self._voicemailLocationRegex.search(messageHtml)
@@ -605,7 +605,7 @@ class GVoiceBackend(object):
 
                        exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
                        exactTimeText = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
-                       conv.time = datetime.datetime.strptime(exactTimeText, "%m/%d/%y %I:%M %p")
+                       conv.time = google_strptime(exactTimeText)
                        relativeTimeGroup = self._relativeVoicemailTimeRegex.search(messageHtml)
                        conv.relTime = relativeTimeGroup.group(1).strip() if relativeTimeGroup else ""
                        locationGroup = self._voicemailLocationRegex.search(messageHtml)
@@ -655,7 +655,7 @@ class GVoiceBackend(object):
 
                        exactTimeGroup = self._exactVoicemailTimeRegex.search(messageHtml)
                        exactTimeText = exactTimeGroup.group(1).strip() if exactTimeGroup else ""
-                       conv.time = datetime.datetime.strptime(exactTimeText, "%m/%d/%y %I:%M %p")
+                       conv.time = google_strptime(exactTimeText)
                        relativeTimeGroup = self._relativeVoicemailTimeRegex.search(messageHtml)
                        conv.relTime = relativeTimeGroup.group(1).strip() if relativeTimeGroup else ""
                        conv.location = ""
@@ -722,6 +722,19 @@ class GVoiceBackend(object):
                return json
 
 
+def google_strptime(time):
+       """
+       Hack: Google always returns the time in the same locale.  Sadly if the
+       local system's locale is different, there isn't a way to perfectly handle
+       the time.  So instead we handle implement some time formatting
+       """
+       abbrevTime = time[:-3]
+       parsedTime = datetime.datetime.strptime(abbrevTime, "%m/%d/%y %I:%M")
+       if time[-2] == "PN":
+               parsedTime += datetime.timedelta(hours=12)
+       return parsedTime
+
+
 def itergroup(iterator, count, padValue = None):
        """
        Iterate in groups of 'count' values. If there