kikocis/java-driver public
Changesets · Branches · Tags · Compare
| Changeset | 461a090f49945323b18dbc38b7ceb44fddebd0992ee05227d432cfb318358ed6 |
|---|---|
| Author | olim7t <omichallat+github@gmail.com> · 2015-12-22 09:56 +01:00 |
| Committer | olim7t <omichallat+github@gmail.com> · 2015-12-22 09:56 +01:00 |
| Parents | c559bbce6d4f |
6 files changed
modified changelog/README.md +0 −1
| @@ -3,7 +3,6 @@ | ||
| 3 | 3 | ### 3.0.0-rc1 (in progress) |
| 4 | 4 | |
| 5 | 5 | - [bug] JAVA-890: fix mapper for case-sensitive UDT. |
| 6 | -- [improvement] JAVA-1013: TimestampCodec should format dates in human-readable format. | |
| 7 | 6 | |
| 8 | 7 | |
| 9 | 8 | ### 3.0.0-beta1 |
modified driver-core/src/main/java/com/datastax/driver/core/ParseUtils.java +0 −14
| @@ -324,20 +324,6 @@ | ||
| 324 | 324 | throw new ParseException("Unable to parse the date: " + str, -1); |
| 325 | 325 | } |
| 326 | 326 | |
| 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 | - | |
| 341 | 327 | /** |
| 342 | 328 | * Parse the given string as a time, using the following time pattern: {@code hh:mm:ss[.fffffffff]}. |
| 343 | 329 | * <p/> |
modified driver-core/src/main/java/com/datastax/driver/core/TypeCodec.java +1 −5
| @@ -1406,10 +1406,6 @@ | ||
| 1406 | 1406 | |
| 1407 | 1407 | private static final TimestampCodec instance = new TimestampCodec(); |
| 1408 | 1408 | |
| 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 | - | |
| 1413 | 1409 | private TimestampCodec() { |
| 1414 | 1410 | super(DataType.timestamp(), Date.class); |
| 1415 | 1411 | } |
| @@ -1441,7 +1437,7 @@ | ||
| 1441 | 1437 | public String format(Date value) { |
| 1442 | 1438 | if (value == null) |
| 1443 | 1439 | return "NULL"; |
| 1444 | - return ParseUtils.quote(ParseUtils.formatDate(value, UTC, PATTERN)); | |
| 1440 | + return Long.toString(value.getTime()); | |
| 1445 | 1441 | } |
| 1446 | 1442 | |
| 1447 | 1443 | @Override |
modified driver-core/src/test/java/com/datastax/driver/core/DataTypeTest.java +4 −11
| @@ -26,8 +26,6 @@ | ||
| 26 | 26 | import java.util.*; |
| 27 | 27 | |
| 28 | 28 | 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; | |
| 31 | 29 | import static com.google.common.collect.Lists.newArrayList; |
| 32 | 30 | import static org.testng.Assert.assertEquals; |
| 33 | 31 | import static org.testng.Assert.fail; |
| @@ -41,11 +39,6 @@ | ||
| 41 | 39 | |
| 42 | 40 | ProtocolVersion protocolVersion = TestUtils.getDesiredProtocolVersion(); |
| 43 | 41 | |
| 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 | - | |
| 49 | 42 | static boolean exclude(DataType t) { |
| 50 | 43 | return t.getName() == DataType.Name.COUNTER; |
| 51 | 44 | } |
| @@ -92,10 +85,10 @@ | ||
| 92 | 85 | case TIMESTAMP: |
| 93 | 86 | // input: single quotes are optional for long literals, mandatory for date patterns |
| 94 | 87 | 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"), | |
| 99 | 92 | new TestValue(null, null, "NULL"), new TestValue(null, "null", "NULL"), new TestValue(null, "NULL", "NULL")}; |
| 100 | 93 | case DATE: |
| 101 | 94 | // 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 @@ | ||
| 26 | 26 | import org.testng.annotations.Test; |
| 27 | 27 | |
| 28 | 28 | import java.nio.ByteBuffer; |
| 29 | -import java.text.ParseException; | |
| 30 | 29 | import java.util.*; |
| 31 | 30 | |
| 32 | 31 | import static com.datastax.driver.core.Assertions.assertThat; |
| @@ -253,24 +252,6 @@ | ||
| 253 | 252 | .cannotFormat(type4UUID); |
| 254 | 253 | } |
| 255 | 254 | |
| 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 | - } | |
| 274 | 255 | |
| 275 | 256 | /** |
| 276 | 257 | * 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 @@ | ||
| 121 | 121 | |
| 122 | 122 | Date date = new Date(); |
| 123 | 123 | 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;"; | |
| 125 | 125 | select = select().all().from("foo").where(eq("d", date)); |
| 126 | 126 | assertEquals(select.toString(), query); |
| 127 | 127 |