From 8fe27eff5838caf35a79daa9f8ea537bb19b79e6 Mon Sep 17 00:00:00 2001 From: Jacky Date: Sat, 12 May 2018 20:19:55 -0400 Subject: [PATCH] use yyyy-mm-dd formatter when converting date to string --- main/src/com/google/refine/expr/functions/ToString.java | 2 +- main/src/com/google/refine/util/StringUtils.java | 4 ++-- .../expr/functions/strings/ToFromConversionTests.java | 9 ++++++--- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/main/src/com/google/refine/expr/functions/ToString.java b/main/src/com/google/refine/expr/functions/ToString.java index 974d48c0a..d8e67ebfc 100644 --- a/main/src/com/google/refine/expr/functions/ToString.java +++ b/main/src/com/google/refine/expr/functions/ToString.java @@ -55,7 +55,7 @@ public class ToString implements Function { Object o2 = args[1]; if (o1 instanceof OffsetDateTime) { OffsetDateTime odt = (OffsetDateTime)o1; - return odt.format(DateTimeFormatter.ISO_INSTANT); + return odt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } else if (o1 instanceof Number) { return String.format((String) o2, (Number) o1); } diff --git a/main/src/com/google/refine/util/StringUtils.java b/main/src/com/google/refine/util/StringUtils.java index 2bfc5a910..d9db618ca 100644 --- a/main/src/com/google/refine/util/StringUtils.java +++ b/main/src/com/google/refine/util/StringUtils.java @@ -6,7 +6,7 @@ import java.time.format.DateTimeFormatter; public class StringUtils { /** - * String formatting method that knows how to format dates (using the defaul locale's date formatter) + * String formatting method that knows how to format dates (using the default locale's date formatter) * @param o object to be converted to a string * @return string representing object */ @@ -14,7 +14,7 @@ public class StringUtils { // to replace the DateFormat with java.time.format.DateTimeFormatter if (o instanceof OffsetDateTime) { OffsetDateTime odt = (OffsetDateTime)o; - return odt.format(DateTimeFormatter.ISO_INSTANT); + return odt.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")); } else if (o == null) { return "null"; } else { diff --git a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java index 23b139e59..06996c30e 100644 --- a/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java +++ b/main/tests/server/src/com/google/refine/tests/expr/functions/strings/ToFromConversionTests.java @@ -117,9 +117,12 @@ public class ToFromConversionTests extends RefineTest { Assert.assertEquals(invoke("toString", Double.valueOf(100.0)),"100.0"); Assert.assertEquals(invoke("toString", Double.valueOf(100.0),"%.0f"),"100"); - String expectedDate = "2013-06-01T00:00:00Z"; - Assert.assertEquals(invoke("toString", CalenderParser.parseAsOffsetDateTime("2013-06-01")), expectedDate); - Assert.assertEquals(invoke("toString", CalenderParser.parseAsOffsetDateTime("2013-06-01"),"yyyy-MM-dd"),expectedDate); + String intputDate = "2013-06-01"; + String expectedDate = "2013-06-01"; + Assert.assertEquals(invoke("toString", CalenderParser.parseAsOffsetDateTime(intputDate)), + expectedDate); + Assert.assertEquals(invoke("toString", CalenderParser.parseAsOffsetDateTime(intputDate), "yyyy-MM-dd"), + expectedDate); } @Test