Elffuss BraidHub

kikocis/java-driver public

Revert JAVA-1013 (TimestampCodec should format dates in human-readable).

The new format wasn't compatible with older versions of Cassandra.

This reverts commit 49b6bb2019069a81439c6aed5d51ca699d917ead, reversing
changes made to 7f889d96180588cae358689577b1c03450635a40.
Changeset461a090f49945323b18dbc38b7ceb44fddebd0992ee05227d432cfb318358ed6
Authorolim7t <omichallat+github@gmail.com> · 2015-12-22 09:56 +01:00
Committerolim7t <omichallat+github@gmail.com> · 2015-12-22 09:56 +01:00
Parentsc559bbce6d4f

Browse the files at this changeset

6 files changed

modified changelog/README.md +0 −1
@@ -3,7 +3,6 @@
33 ### 3.0.0-rc1 (in progress)
44
55 - [bug] JAVA-890: fix mapper for case-sensitive UDT.
6-- [improvement] JAVA-1013: TimestampCodec should format dates in human-readable format.
76
87
98 ### 3.0.0-beta1
modified driver-core/src/main/java/com/datastax/driver/core/ParseUtils.java +0 −14
@@ -324,20 +324,6 @@
324324 throw new ParseException("Unable to parse the date: " + str, -1);
325325 }
326326
327- /**
328- * Formats the given date, using the given time zone and the given pattern.
329- *
330- * @param date The date to format.
331- * @param timeZone The time zone to use.
332- * @param pattern The date pattern to use.
333- * @return The formatted date.
334- */
335- public static String formatDate(Date date, TimeZone timeZone, String pattern) {
336- SimpleDateFormat formatter = new SimpleDateFormat(pattern);
337- formatter.setTimeZone(timeZone);
338- return formatter.format(date);
339- }
340-
341327 /**
342328 * Parse the given string as a time, using the following time pattern: {@code hh:mm:ss[.fffffffff]}.
343329 * <p/>
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +1 −5
@@ -1406,10 +1406,6 @@
14061406
14071407 private static final TimestampCodec instance = new TimestampCodec();
14081408
1409- private static final String PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
1410-
1411- private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
1412-
14131409 private TimestampCodec() {
14141410 super(DataType.timestamp(), Date.class);
14151411 }
@@ -1441,7 +1437,7 @@
14411437 public String format(Date value) {
14421438 if (value == null)
14431439 return "NULL";
1444- return ParseUtils.quote(ParseUtils.formatDate(value, UTC, PATTERN));
1440+ return Long.toString(value.getTime());
14451441 }
14461442
14471443 @Override
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +4 −11
@@ -26,8 +26,6 @@
2626 import java.util.*;
2727
2828 import static com.datastax.driver.core.Assertions.assertThat;
29-import static com.datastax.driver.core.ParseUtils.formatDate;
30-import static com.datastax.driver.core.ParseUtils.quote;
3129 import static com.google.common.collect.Lists.newArrayList;
3230 import static org.testng.Assert.assertEquals;
3331 import static org.testng.Assert.fail;
@@ -41,11 +39,6 @@
4139
4240 ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion();
4341
44- private static final String PATTERN = "yyyy-MM-dd'T'HH:mm:ss.SSSZ";
45-
46- private static final TimeZone UTC = TimeZone.getTimeZone("UTC");
47-
48-
4942 static boolean exclude(DataType t) {
5043 return t.getName() == DataType.Name.COUNTER;
5144 }
@@ -92,10 +85,10 @@
9285 case TIMESTAMP:
9386 // input: single quotes are optional for long literals, mandatory for date patterns
9487 return new TestValue[]{
95- new TestValue(new Date(42L), "42", quote(formatDate(new Date(42L), UTC, PATTERN))),
96- new TestValue(new Date(91294377723L), "91294377723", quote(formatDate(new Date(91294377723L), UTC, PATTERN))),
97- new TestValue(new Date(-133L), "-133", quote(formatDate(new Date(-133L), UTC, PATTERN))),
98- new TestValue(new Date(784041330999L), "'1994-11-05T14:15:30.999+0100'", quote(formatDate(new Date(784041330999L), UTC, PATTERN))),
88+ new TestValue(new Date(42L), "42", "42"),
89+ new TestValue(new Date(91294377723L), "91294377723", "91294377723"),
90+ new TestValue(new Date(-133L), "-133", "-133"),
91+ new TestValue(new Date(784041330999L), "'1994-11-05T14:15:30.999+0100'", "784041330999"),
9992 new TestValue(null, null, "NULL"), new TestValue(null, "null", "NULL"), new TestValue(null, "NULL", "NULL")};
10093 case DATE:
10194 // input: single quotes are optional for long literals, mandatory for date patterns
modified driver-core/src/test/java/com/datastax/driver/core/TypeCodecTest.java +0 −19
@@ -26,7 +26,6 @@
2626 import org.testng.annotations.Test;
2727
2828 import java.nio.ByteBuffer;
29-import java.text.ParseException;
3029 import java.util.*;
3130
3231 import static com.datastax.driver.core.Assertions.assertThat;
@@ -253,24 +252,6 @@
253252 .cannotFormat(type4UUID);
254253 }
255254
256- @Test(groups = "unit")
257- public void should_format_timestamp_with_iso8601_pattern() throws ParseException {
258- // given
259- // 2015 Dec 7th, 17:53:46.999, at UTC-7
260- GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("GMT-7:00"));
261- cal.set(Calendar.YEAR, 2015);
262- cal.set(Calendar.MONTH, 11);
263- cal.set(Calendar.DAY_OF_MONTH, 7);
264- cal.set(Calendar.HOUR_OF_DAY, 17);
265- cal.set(Calendar.MINUTE, 53);
266- cal.set(Calendar.SECOND, 46);
267- cal.set(Calendar.MILLISECOND, 999);
268- Date date = cal.getTime();
269- // when
270- String formatted = TypeCodec.timestamp().format(date);
271- // then
272- assertThat(formatted).isEqualTo("'2015-12-08T00:53:46.999+0000'");
273- }
274255
275256 /**
276257 * Ensures that primitive types are correctly handled and wrapped when necessary.
modified driver-core/src/test/java/com/datastax/driver/core/querybuilder/QueryBuilderTest.java +1 −1
@@ -121,7 +121,7 @@
121121
122122 Date date = new Date();
123123 date.setTime(1234325);
124- query = "SELECT * FROM foo WHERE d='1970-01-01T00:20:34.325+0000';";
124+ query = "SELECT * FROM foo WHERE d=1234325;";
125125 select = select().all().from("foo").where(eq("d", date));
126126 assertEquals(select.toString(), query);
127127