CachedDateFormat: Correct fix for handling ts with 654 as ms part

The previous commit [1] tried to fix the issue that findMillisecondStart
does not work correctly when the millisecond part of the timestamp is
654 ms. However, it only fixed the issue for the special case when the
millisecond part was 654 and the microsecond part was 0, even though the
microseconds should not matter.

Fix this by comparing in milliseconds instead of in microseconds.

Fixes LOGCXX-506.

[1]: 396c8abfe92136db6ba2453bf804ba8ca48a923d
diff --git a/src/main/cpp/cacheddateformat.cpp b/src/main/cpp/cacheddateformat.cpp
index c813ece..6413baf 100644
--- a/src/main/cpp/cacheddateformat.cpp
+++ b/src/main/cpp/cacheddateformat.cpp
@@ -124,13 +124,12 @@
 		slotBegin -= 1000000;
 	}
 
-	int micros = (int) (time - slotBegin);
+	int millis = (int) (time - slotBegin) / 1000;
 
 	// the magic numbers are in microseconds
 	int magic = magic1;
 	LogString magicString(magicString1);
-
-	if (micros == magic1)
+	if (millis == magic1 / 1000)
 	{
 		magic = magic2;
 		magicString = magicString2;
@@ -158,7 +157,7 @@
 				//   determine the expected digits for the base time
 				const logchar abc[] = { 0x41, 0x42, 0x43, 0 };
 				LogString formattedMillis(abc);
-				millisecondFormat(micros / 1000, formattedMillis, 0);
+				millisecondFormat(millis, formattedMillis, 0);
 
 				LogString plusZero;
 				formatter->format(plusZero, slotBegin, pool);
diff --git a/src/test/cpp/helpers/cacheddateformattestcase.cpp b/src/test/cpp/helpers/cacheddateformattestcase.cpp
index 7148834..74d180e 100644
--- a/src/test/cpp/helpers/cacheddateformattestcase.cpp
+++ b/src/test/cpp/helpers/cacheddateformattestcase.cpp
@@ -662,6 +662,14 @@
     formatted.clear();
     isoFormat.format(formatted, 999000, p);
     LOGUNIT_ASSERT_EQUAL(LOG4CXX_STR("1970-01-01 00:00:00,999"), formatted);
+
+    formatted.clear();
+    isoFormat.format(formatted, 1654010, p);
+    LOGUNIT_ASSERT_EQUAL(LOG4CXX_STR("1970-01-01 00:00:01,654"), formatted);
+
+    formatted.clear();
+    isoFormat.format(formatted, 1999010, p);
+    LOGUNIT_ASSERT_EQUAL(LOG4CXX_STR("1970-01-01 00:00:01,999"), formatted);
 }
 
 };