Avoid localizing time for dates with unspecified time. Closes #1874.
This commit is contained in:
parent
85887372ae
commit
44c43253a1
@ -37,6 +37,7 @@ import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.time.OffsetDateTime;
|
||||
import java.time.ZoneOffset;
|
||||
import java.time.ZonedDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.GregorianCalendar;
|
||||
@ -166,7 +167,9 @@ public class ToDate implements Function {
|
||||
return date;
|
||||
} else {
|
||||
try {
|
||||
return javax.xml.bind.DatatypeConverter.parseDateTime(o1).getTime().toInstant().atOffset(ZoneOffset.of("Z"));
|
||||
return javax.xml.bind.DatatypeConverter.parseDateTime(o1).getTime().toInstant()
|
||||
.plusSeconds(ZonedDateTime.now().getOffset().getTotalSeconds())
|
||||
.atOffset(ZoneOffset.of("Z"));
|
||||
} catch (IllegalArgumentException e2) {
|
||||
return null;
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ import com.google.refine.expr.util.CalendarParserException;
|
||||
import com.google.refine.grel.ControlFunctionRegistry;
|
||||
import com.google.refine.grel.Function;
|
||||
import com.google.refine.tests.RefineTest;
|
||||
import com.google.refine.util.ParsingUtilities;
|
||||
|
||||
|
||||
/**
|
||||
@ -161,10 +162,10 @@ public class ToFromConversionTests extends RefineTest {
|
||||
Assert.assertEquals(invoke("toDate", "01-六月-2013","zh","dd-MMM-yyyy"), CalendarParser.parseAsOffsetDateTime("2013-06-01"));
|
||||
|
||||
//if invalid format/locale strings are passed, ignore them
|
||||
Assert.assertEquals(invoke("toDate", "2012-03-01","XXX"), CalendarParser.parseAsOffsetDateTime("2012-03-01"));
|
||||
Assert.assertEquals(invoke("toDate", "2012-03-01","XXX"), invoke("toDate", "2012-03-01"));
|
||||
|
||||
// If a long, convert to string
|
||||
Assert.assertEquals(invoke("toDate", (long) 2012), CalendarParser.parseAsOffsetDateTime("2012-01-01"));
|
||||
Assert.assertEquals(invoke("toDate", (long) 2012), invoke("toDate", "2012-01-01"));
|
||||
|
||||
// If already a date, leave it alone
|
||||
Assert.assertEquals(invoke("toDate", CalendarParser.parseAsOffsetDateTime("2012-03-01")),CalendarParser.parseAsOffsetDateTime("2012-03-01"));
|
||||
|
Loading…
Reference in New Issue
Block a user