Reviewers: scottb,
Description:
Once again allow Dates from doubles, for JSON happiness
Review by: [email protected]
Please review this at http://gwt-code-reviews.appspot.com/202801
Affected files:
M bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
M user/super/com/google/gwt/emul/java/util/Date.java
Index: bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java
===================================================================
--- bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java (revision
7725)
+++ bikeshed/src/com/google/gwt/valuestore/client/ValuesImpl.java (working
copy)
@@ -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) /*-{
-// [email protected]::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];
Index: user/super/com/google/gwt/emul/java/util/Date.java
===================================================================
--- user/super/com/google/gwt/emul/java/util/Date.java (revision 7725)
+++ user/super/com/google/gwt/emul/java/util/Date.java (working copy)
@@ -93,6 +93,21 @@
jsdate = JsDate.create(date);
}
+ /**
+ * 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);
+ }
+
public Date(String date) {
this(Date.parse(date));
}
--
http://groups.google.com/group/Google-Web-Toolkit-Contributors