/pidgin/main: 6a1aea2866aa: Refactor an error path in purple_str...

Richard Laager rlaager at pidgin.im
Tue Jun 25 01:02:39 EDT 2013


Changeset: 6a1aea2866aa663df5958cea6c01f0dbe1f606c2
Author:	 Richard Laager <rlaager at pidgin.im>
Date:	 2013-06-24 22:36 -0500
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/6a1aea2866aa

Description:

Refactor an error path in purple_str_to_time()

I see no reason to return 0 on a timestamp that ends in a "+" or "-"
without a timestamp.  Instead, we can just ignore the sign and treat it
like any other timestamp without a timezone.

diffstat:

 libpurple/util.c |  29 ++++++++++++++++-------------
 1 files changed, 16 insertions(+), 13 deletions(-)

diffs (54 lines):

diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -706,7 +706,7 @@ purple_str_to_time(const char *timestamp
 	gint year = 0;
 	long tzoff = PURPLE_NO_TZ_OFF;
 	time_t retval;
-	gboolean mktime_with_utc = TRUE;
+	gboolean mktime_with_utc = FALSE;
 
 	if (rest != NULL)
 		*rest = NULL;
@@ -816,26 +816,29 @@ purple_str_to_time(const char *timestamp
 				if (((sscanf(str, "%02d:%02d", &tzhrs, &tzmins) == 2 && (str += 5)) ||
 					(sscanf(str, "%02d%02d", &tzhrs, &tzmins) == 2 && (str += 4))))
 				{
+					mktime_with_utc = TRUE;
 					tzoff = tzhrs * 60 * 60 + tzmins * 60;
 					tzoff *= sign;
-				} else {
-					if (rest != NULL && *str != '\0')
-						*rest = str;
-
-					return 0;
 				}
 			} else if (*str == 'Z') {
 				/* 'Z' = Zulu = UTC */
 				str++;
-				utc = TRUE;
-			} else if (!utc) {
-				/* Local Time */
-				t.tm_isdst = -1;
-				mktime_with_utc = FALSE;
+				mktime_with_utc = TRUE;
+				tzoff = 0;
 			}
 
-			if (utc)
-				tzoff = 0;
+			if (!mktime_with_utc)
+			{
+				/* No timezone specified. */
+
+				if (utc) {
+					mktime_with_utc = TRUE;
+					tzoff = 0;
+				} else {
+					/* Local Time */
+					t.tm_isdst = -1;
+				}
+			}
 		}
 	}
 



More information about the Commits mailing list