/pidgin/main: e5c1b7f9486d: Fix purple_str_to_time() again.

Richard Laager rlaager at pidgin.im
Tue Jan 21 19:29:32 EST 2014


Changeset: e5c1b7f9486d00320a72eb936e2bf6fbc8ff3bd0
Author:	 Richard Laager <rlaager at pidgin.im>
Date:	 2014-01-21 18:28 -0600
Branch:	 release-2.x.y
URL: https://hg.pidgin.im/pidgin/main/rev/e5c1b7f9486d

Description:

Fix purple_str_to_time() again.

Mark pointed out that the 2010-08-27.134202-0700PDT test was failing.
I've expanded that test to check the various returned parameters
(other than the struct tm).

Before 6a74f42c8c04: the returned time_t is (on my system) off by
an hour.  (It returned 1282938122 instead of 1282941722.)  This was
reported in #13131.

6a74f42c8c04 fixed that, but switched the sign on the returned tz_off.
This was reported as a bug in #15675.

I fixed that in f93f8b0f36c3, but that broke the tests.  Mark reported
it was returning 1282891322.

This commit fixes that, while not breaking the tz_off.

diffstat:

 libpurple/tests/test_util.c |  11 ++++++++++-
 libpurple/util.c            |   2 +-
 2 files changed, 11 insertions(+), 2 deletions(-)

diffs (36 lines):

diff --git a/libpurple/tests/test_util.c b/libpurple/tests/test_util.c
--- a/libpurple/tests/test_util.c
+++ b/libpurple/tests/test_util.c
@@ -156,10 +156,19 @@ END_TEST
 
 START_TEST(test_util_str_to_time)
 {
+	struct tm tm;
+	long tz_off;
+	const char *rest;
+	time_t timestamp;
+
 	fail_unless(377182200 == purple_str_to_time("19811214T12:50:00", TRUE, NULL, NULL, NULL));
 	fail_unless(1175919261 == purple_str_to_time("20070407T04:14:21", TRUE, NULL, NULL, NULL));
 	fail_unless(1282941722 == purple_str_to_time("2010-08-27.204202", TRUE, NULL, NULL, NULL));
-	fail_unless(1282941722 == purple_str_to_time("2010-08-27.134202-0700PDT", FALSE, NULL, NULL, NULL));
+
+	timestamp = purple_str_to_time("2010-08-27.134202-0700PDT", FALSE, &tm, &tz_off, &rest);
+	fail_unless(1282941722 == timestamp);
+	fail_unless((-7 * 60 * 60) == tz_off);
+	assert_string_equal("PDT", rest);
 }
 END_TEST
 
diff --git a/libpurple/util.c b/libpurple/util.c
--- a/libpurple/util.c
+++ b/libpurple/util.c
@@ -860,7 +860,7 @@ purple_str_to_time(const char *timestamp
 		*tm = t;
 
 	if (tzoff != PURPLE_NO_TZ_OFF)
-		retval += tzoff;
+		retval -= tzoff;
 
 	if (tz_off != NULL)
 		*tz_off = tzoff;



More information about the Commits mailing list