Once again allow Dates from doubles, for JSON happiness
Review at http://gwt-code-reviews.appspot.com/202801
Review by: scottb@google.com
git-svn-id: https://google-web-toolkit.googlecode.com/svn/trunk@7727 8db76d5a-ed1c-0410-87a9-c151d255dfc7
diff --git a/bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java b/bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
index 5aa0ddb..74286ce 100644
--- a/bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
+++ b/bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
@@ -15,6 +15,7 @@
*/
package com.google.gwt.valuestore.client;
+import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.JavaScriptObject;
import com.google.gwt.core.client.JsArray;
import com.google.gwt.valuestore.shared.Property;
@@ -48,13 +49,12 @@
}
if (Date.class.equals(property.getValueType())) {
double millis = getDouble(property.getName());
- // TODO (rjrjr) bring this back when Date gets JSO friendly again
-// if (GWT.isScript()) {
-// return (V) initDate(new Date(), millis);
-// } else {
+ if (GWT.isScript()) {
+ return (V) dateForDouble(millis);
+ } else {
// In dev mode, we're using real JRE dates
return (V) new Date((long) millis);
-// }
+ }
}
return nativeGet(property);
@@ -89,10 +89,9 @@
return this[name];
}-*/;
-// private native Date initDate(Date date, double millis) /*-{
-// date.@java.util.Date::init(D)(millis);
-// return date;
-// }-*/;
+ private native Date dateForDouble(double millis) /*-{
+ return @java.util.Date::createFrom(D)(millis);
+ }-*/;
private native int getInt(String name) /*-{
return this[name];
diff --git a/user/super/com/google/gwt/emul/java/util/Date.java b/user/super/com/google/gwt/emul/java/util/Date.java
index f54ed3c..025b0a5 100644
--- a/user/super/com/google/gwt/emul/java/util/Date.java
+++ b/user/super/com/google/gwt/emul/java/util/Date.java
@@ -248,6 +248,21 @@
*/
/**
+ * Package private factory for JSNI use, to allow cheap creation of dates from
+ * doubles.
+ */
+ static Date createFrom(double milliseconds) {
+ return new Date(milliseconds, false);
+ }
+
+ /**
+ * For use by {@link #createFrom(double)}, should inline away.
+ */
+ Date(double milliseconds, boolean dummyArgForOverloadResolution) {
+ jsdate = JsDate.create(milliseconds);
+ }
+
+ /**
* Detects if the requested time falls into a non-existent time range due to
* local time advancing into daylight savings time. If so, push the requested
* time forward out of the non-existent range.