use yyyy-mm-dd formatter when converting date to string
This commit is contained in:
parent
cf5c884ca0
commit
8fe27eff58
@ -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);
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user