This commit is contained in:
parent
0258dc1787
commit
2afdcbf546
@ -1,15 +1,15 @@
|
|||||||
eclipse.preferences.version=1
|
eclipse.preferences.version=1
|
||||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||||
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
|
||||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
|
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
|
||||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||||
org.eclipse.jdt.core.compiler.compliance=1.7
|
org.eclipse.jdt.core.compiler.compliance=1.8
|
||||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||||
org.eclipse.jdt.core.compiler.source=1.7
|
org.eclipse.jdt.core.compiler.source=1.8
|
||||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
|
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation=0
|
||||||
|
@ -37,7 +37,7 @@ import java.io.IOException;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -214,10 +214,10 @@ public class PreviewExpressionCommand extends Command {
|
|||||||
Calendar c = (Calendar) v;
|
Calendar c = (Calendar) v;
|
||||||
|
|
||||||
sb.append("[date " +
|
sb.append("[date " +
|
||||||
ParsingUtilities.dateToString(ZonedDateTime.ofInstant(c.toInstant(), ZoneId.systemDefault())) +"]");
|
ParsingUtilities.dateToString(OffsetDateTime.ofInstant(c.toInstant(), ZoneId.systemDefault())) +"]");
|
||||||
} else if (v instanceof LocalDateTime) {
|
} else if (v instanceof LocalDateTime) {
|
||||||
sb.append("[date " +
|
sb.append("[date " +
|
||||||
ParsingUtilities.dateToString((ZonedDateTime) v) +"]");
|
ParsingUtilities.dateToString((OffsetDateTime) v) +"]");
|
||||||
} else if (v instanceof String) {
|
} else if (v instanceof String) {
|
||||||
if (quote) {
|
if (quote) {
|
||||||
sb.append(JSONObject.quote((String) v));
|
sb.append(JSONObject.quote((String) v));
|
||||||
|
@ -35,7 +35,7 @@ package com.google.refine.expr.functions;
|
|||||||
|
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.GregorianCalendar;
|
import java.util.GregorianCalendar;
|
||||||
@ -84,7 +84,7 @@ public class ToDate implements Function {
|
|||||||
try {
|
try {
|
||||||
return CalendarParser.parse( o1, (month_first) ? CalendarParser.MM_DD_YY : CalendarParser.DD_MM_YY);
|
return CalendarParser.parse( o1, (month_first) ? CalendarParser.MM_DD_YY : CalendarParser.DD_MM_YY);
|
||||||
} catch (CalendarParserException e) {
|
} catch (CalendarParserException e) {
|
||||||
ZonedDateTime d = ParsingUtilities.stringToDate(o1);
|
OffsetDateTime d = ParsingUtilities.stringToDate(o1);
|
||||||
if (d != null) {
|
if (d != null) {
|
||||||
return d;
|
return d;
|
||||||
} else {
|
} else {
|
||||||
|
@ -35,7 +35,7 @@ package com.google.refine.history;
|
|||||||
|
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -60,7 +60,7 @@ public class HistoryEntry implements Jsonizable {
|
|||||||
final public long id;
|
final public long id;
|
||||||
final public long projectID;
|
final public long projectID;
|
||||||
final public String description;
|
final public String description;
|
||||||
final public ZonedDateTime time;
|
final public OffsetDateTime time;
|
||||||
|
|
||||||
// the manager (deals with IO systems or databases etc.)
|
// the manager (deals with IO systems or databases etc.)
|
||||||
final public HistoryEntryManager _manager;
|
final public HistoryEntryManager _manager;
|
||||||
@ -86,11 +86,11 @@ public class HistoryEntry implements Jsonizable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public HistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change) {
|
public HistoryEntry(long id, Project project, String description, AbstractOperation operation, Change change) {
|
||||||
this(id,project.id,description,operation,ZonedDateTime.now(ZoneId.of("Z")));
|
this(id,project.id,description,operation,OffsetDateTime.now(ZoneId.of("Z")));
|
||||||
setChange(change);
|
setChange(change);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HistoryEntry(long id, long projectID, String description, AbstractOperation operation, ZonedDateTime time) {
|
protected HistoryEntry(long id, long projectID, String description, AbstractOperation operation, OffsetDateTime time) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.projectID = projectID;
|
this.projectID = projectID;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
|
@ -36,7 +36,7 @@ package com.google.refine.model;
|
|||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
@ -90,8 +90,8 @@ public class Cell implements HasFields, Jsonizable {
|
|||||||
if (value instanceof LocalDateTime) {
|
if (value instanceof LocalDateTime) {
|
||||||
writer.value(ParsingUtilities.localDateToString((LocalDateTime)value));
|
writer.value(ParsingUtilities.localDateToString((LocalDateTime)value));
|
||||||
writer.key("t"); writer.value("date");
|
writer.key("t"); writer.value("date");
|
||||||
} else if (value instanceof ZonedDateTime) {
|
} else if (value instanceof OffsetDateTime) {
|
||||||
writer.value(ParsingUtilities.dateToString((ZonedDateTime) value));
|
writer.value(ParsingUtilities.dateToString((OffsetDateTime) value));
|
||||||
writer.key("t"); writer.value("date");
|
writer.key("t"); writer.value("date");
|
||||||
} else if (value instanceof Double
|
} else if (value instanceof Double
|
||||||
&& (((Double)value).isNaN() || ((Double)value).isInfinite())) {
|
&& (((Double)value).isNaN() || ((Double)value).isInfinite())) {
|
||||||
|
@ -39,7 +39,7 @@ import java.io.StringWriter;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -310,10 +310,10 @@ public class StandardReconConfig extends ReconConfig {
|
|||||||
jsonWriter.endObject();
|
jsonWriter.endObject();
|
||||||
} else if (cell2.value instanceof Calendar) {
|
} else if (cell2.value instanceof Calendar) {
|
||||||
Calendar calendar = (Calendar) cell2.value;
|
Calendar calendar = (Calendar) cell2.value;
|
||||||
ZonedDateTime d = ZonedDateTime.ofInstant(calendar.toInstant(), ZoneId.of("Z"));
|
OffsetDateTime d = OffsetDateTime.ofInstant(calendar.toInstant(), ZoneId.of("Z"));
|
||||||
jsonWriter.value(ParsingUtilities.dateToString(d));
|
jsonWriter.value(ParsingUtilities.dateToString(d));
|
||||||
} else if (cell2.value instanceof Date) {
|
} else if (cell2.value instanceof Date) {
|
||||||
jsonWriter.value(ParsingUtilities.dateToString((ZonedDateTime) cell2.value));
|
jsonWriter.value(ParsingUtilities.dateToString((OffsetDateTime) cell2.value));
|
||||||
} else {
|
} else {
|
||||||
jsonWriter.value(cell2.value.toString());
|
jsonWriter.value(cell2.value.toString());
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ package com.google.refine.util;
|
|||||||
|
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
@ -97,9 +97,9 @@ public class JSONUtilities {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static public ZonedDateTime getDate(JSONObject obj, String key, ZonedDateTime def) {
|
static public OffsetDateTime getDate(JSONObject obj, String key, OffsetDateTime def) {
|
||||||
try {
|
try {
|
||||||
ZonedDateTime d = ParsingUtilities.stringToDate(obj.getString(key));
|
OffsetDateTime d = ParsingUtilities.stringToDate(obj.getString(key));
|
||||||
|
|
||||||
return d != null ? d : def;
|
return d != null ? d : def;
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -193,9 +193,9 @@ public class JSONUtilities {
|
|||||||
} else if (value instanceof Boolean) {
|
} else if (value instanceof Boolean) {
|
||||||
obj.put(key, value);
|
obj.put(key, value);
|
||||||
} else if (value instanceof Date) {
|
} else if (value instanceof Date) {
|
||||||
obj.put(key, ParsingUtilities.dateToString((ZonedDateTime) value));
|
obj.put(key, ParsingUtilities.dateToString((OffsetDateTime) value));
|
||||||
} else if (value instanceof Calendar) {
|
} else if (value instanceof Calendar) {
|
||||||
obj.put(key, ParsingUtilities.dateToString(ZonedDateTime.ofInstant(((Calendar)value).toInstant(), ZoneId.of("Z"))));
|
obj.put(key, ParsingUtilities.dateToString(OffsetDateTime.ofInstant(((Calendar)value).toInstant(), ZoneId.of("Z"))));
|
||||||
} else if (value instanceof String) {
|
} else if (value instanceof String) {
|
||||||
obj.put(key, value);
|
obj.put(key, value);
|
||||||
} else {
|
} else {
|
||||||
|
@ -40,7 +40,7 @@ import java.io.Reader;
|
|||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.time.format.DateTimeFormatter;
|
import java.time.format.DateTimeFormatter;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
@ -174,9 +174,8 @@ public class ParsingUtilities {
|
|||||||
* @param d the date to be written
|
* @param d the date to be written
|
||||||
* @return string with ISO_LOCAL_DATE_TIME formatted date & time
|
* @return string with ISO_LOCAL_DATE_TIME formatted date & time
|
||||||
*/
|
*/
|
||||||
static public String dateToString(ZonedDateTime d) {
|
static public String dateToString(OffsetDateTime d) {
|
||||||
// return d.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
return d.format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
return d.format(DateTimeFormatter.ISO_INSTANT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public String localDateToString(LocalDateTime d) {
|
static public String localDateToString(LocalDateTime d) {
|
||||||
@ -189,9 +188,8 @@ public class ParsingUtilities {
|
|||||||
* @param s the string to be parsed
|
* @param s the string to be parsed
|
||||||
* @return LocalDateTime or null if the parse failed
|
* @return LocalDateTime or null if the parse failed
|
||||||
*/
|
*/
|
||||||
static public ZonedDateTime stringToDate(String s) {
|
static public OffsetDateTime stringToDate(String s) {
|
||||||
// return LocalDateTime.parse(s, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
|
return OffsetDateTime.parse(s, DateTimeFormatter.ISO_OFFSET_DATE_TIME);
|
||||||
return ZonedDateTime.parse(s, DateTimeFormatter.ISO_INSTANT);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static public LocalDateTime stringToLocalDate(String s) {
|
static public LocalDateTime stringToLocalDate(String s) {
|
||||||
|
@ -42,7 +42,7 @@ import java.io.IOException;
|
|||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
import java.time.ZonedDateTime;
|
import java.time.OffsetDateTime;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -202,7 +202,7 @@ public class CsvExporterTests extends RefineTest {
|
|||||||
public void exportDateColumns(){
|
public void exportDateColumns(){
|
||||||
CreateGrid(1,2);
|
CreateGrid(1,2);
|
||||||
LocalDateTime localDate = LocalDateTime.now();
|
LocalDateTime localDate = LocalDateTime.now();
|
||||||
ZonedDateTime date = ZonedDateTime.now(ZoneId.of("Z"));
|
OffsetDateTime date = OffsetDateTime.now(ZoneId.of("Z"));
|
||||||
|
|
||||||
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
when(options.getProperty("printColumnHeader")).thenReturn("false");
|
||||||
project.rows.get(0).cells.set(0, new Cell(localDate, null));
|
project.rows.get(0).cells.set(0, new Cell(localDate, null));
|
||||||
|
@ -33,6 +33,9 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|||||||
|
|
||||||
package com.google.refine.tests.util;
|
package com.google.refine.tests.util;
|
||||||
|
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
@ -85,4 +88,23 @@ public class ParsingUtilitiesTests extends RefineTest {
|
|||||||
//expected
|
//expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@Test
|
||||||
|
public void zonedDateTimeTest() {
|
||||||
|
// String d = "2017-07-18T20:26:28.582+03:00[Asia/Istanbul]";
|
||||||
|
// DateTimeFormatter formatter = DateTimeFormatter.ISO_ZONED_DATE_TIME ;
|
||||||
|
// OffsetDateTime.parse(d, formatter);
|
||||||
|
String d = "2017-12-01T14:53:36Z";
|
||||||
|
DateTimeFormatter formatter = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
|
||||||
|
OffsetDateTime.parse(d, formatter);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseProjectBeforeJDK8() {
|
||||||
|
String historyEntryDate = "2017-12-01T14:53:36Z";
|
||||||
|
|
||||||
|
OffsetDateTime zdt = ParsingUtilities.stringToDate(historyEntryDate);
|
||||||
|
String zdtString = ParsingUtilities.dateToString(zdt);
|
||||||
|
Assert.assertEquals(zdtString, historyEntryDate);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user