Revision: 10632
Author:   gwt.mirror...@gmail.com
Date:     Thu Sep  8 05:48:56 2011
Log:      Add ability to control time zone in DateCell.

Review at http://gwt-code-reviews.appspot.com/1539803

Review by: jlaba...@google.com
http://code.google.com/p/google-web-toolkit/source/detail?r=10632

Modified:
 /trunk/tools/api-checker/config/gwt23_24userApi.conf
 /trunk/user/src/com/google/gwt/cell/client/DateCell.java
 /trunk/user/test/com/google/gwt/cell/client/DateCellTest.java

=======================================
--- /trunk/tools/api-checker/config/gwt23_24userApi.conf Wed Sep 7 09:32:44 2011 +++ /trunk/tools/api-checker/config/gwt23_24userApi.conf Thu Sep 8 02:20:30 2011
@@ -176,3 +176,6 @@
com.google.gwt.user.cellview.client.AbstractHasData::onUpdateSelection() MISSING com.google.gwt.user.cellview.client.CellList::doSelection(Lcom/google/gwt/user/client/Event;Ljava/lang/Object;I) MISSING com.google.gwt.user.cellview.client.CellTable::doSelection(Lcom/google/gwt/user/client/Event;Ljava/lang/Object;II) MISSING
+
+# Adding timezone constructor argument to DateCell
+com.google.gwt.cell.client.DateCell::DateCell(Lcom/google/gwt/i18n/client/DateTimeFormat;Lcom/google/gwt/text/shared/SafeHtmlRenderer;) OVERLOADED_METHOD_CALL
=======================================
--- /trunk/user/src/com/google/gwt/cell/client/DateCell.java Wed Dec 1 05:40:20 2010 +++ /trunk/user/src/com/google/gwt/cell/client/DateCell.java Thu Sep 8 02:20:30 2011
@@ -17,6 +17,7 @@

 import com.google.gwt.i18n.client.DateTimeFormat;
 import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
+import com.google.gwt.i18n.client.TimeZone;
 import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
 import com.google.gwt.text.shared.SafeHtmlRenderer;
 import com.google.gwt.text.shared.SimpleSafeHtmlRenderer;
@@ -32,13 +33,15 @@

   private final SafeHtmlRenderer<String> renderer;

+  private final TimeZone timeZone;
+
   /**
    * Construct a new {@link DateCell} using the format
* {@link PredefinedFormat#DATE_FULL} and a {@link SimpleSafeHtmlRenderer}.
    */
   public DateCell() {
     this(DateTimeFormat.getFormat(PredefinedFormat.DATE_FULL),
-        SimpleSafeHtmlRenderer.getInstance());
+        SimpleSafeHtmlRenderer.getInstance(), null);
   }

   /**
@@ -49,7 +52,7 @@
    *          formatted date as HTML
    */
   public DateCell(SafeHtmlRenderer<String> renderer) {
-    this(DateTimeFormat.getFormat(PredefinedFormat.DATE_FULL), renderer);
+ this(DateTimeFormat.getFormat(PredefinedFormat.DATE_FULL), renderer, null);
   }

   /**
@@ -59,7 +62,7 @@
    * @param format the {@link DateTimeFormat} used to render the date
    */
   public DateCell(DateTimeFormat format) {
-    this(format, SimpleSafeHtmlRenderer.getInstance());
+    this(format, SimpleSafeHtmlRenderer.getInstance(), null);
   }

   /**
@@ -71,6 +74,36 @@
    *          formatted date
    */
public DateCell(DateTimeFormat format, SafeHtmlRenderer<String> renderer) {
+    this(format, renderer, null);
+  }
+
+  /**
+ * Construct a new {@link DateCell} using the specified format and time zone.
+   *
+   * @param format the {@link DateTimeFormat} used to render the date
+ * @param timezone the {@link TimeZone} used to render the date, or null to + * use the default behavior for the local time zone and the rendered
+   *          date. See {@link DateTimeFormat#format(Date)} and
+   *          {@link Date#getTimeZoneOffset}
+   */
+  public DateCell(DateTimeFormat format, TimeZone timeZone) {
+    this(format, SimpleSafeHtmlRenderer.getInstance(), timeZone);
+  }
+
+  /**
+   * Construct a new {@link DateCell} using the specified format, the given
+   * {@link SafeHtmlRenderer}, and the specified time zone.
+   *
+   * @param format the {@link DateTimeFormat} used to render the date
+   * @param renderer a non-null {@link SafeHtmlRenderer} used to render the
+   *          formatted date
+ * @param timezone the {@link TimeZone} used to render the date, or null to + * use the default behavior for the local time zone and the rendered
+   *          date. See {@link DateTimeFormat#format(Date)} and
+   *          {@link Date#getTimeZoneOffset}
+   */
+  public DateCell(DateTimeFormat format, SafeHtmlRenderer<String> renderer,
+      TimeZone timeZone) {
     if (format == null) {
       throw new IllegalArgumentException("format == null");
     }
@@ -79,12 +112,13 @@
     }
     this.format = format;
     this.renderer = renderer;
+    this.timeZone = timeZone;
   }

   @Override
   public void render(Context context, Date value, SafeHtmlBuilder sb) {
     if (value != null) {
-      sb.append(renderer.render(format.format(value)));
+      sb.append(renderer.render(format.format(value, timeZone)));
     }
   }
 }
=======================================
--- /trunk/user/test/com/google/gwt/cell/client/DateCellTest.java Tue Jul 27 08:47:38 2010 +++ /trunk/user/test/com/google/gwt/cell/client/DateCellTest.java Thu Sep 8 02:20:30 2011
@@ -16,7 +16,7 @@
 package com.google.gwt.cell.client;

 import com.google.gwt.i18n.client.DateTimeFormat;
-import com.google.gwt.i18n.client.DateTimeFormat.PredefinedFormat;
+import com.google.gwt.i18n.client.TimeZone;

 import java.util.Date;

@@ -27,13 +27,17 @@

   @Override
   protected Cell<Date> createCell() {
- return new DateCell(DateTimeFormat.getFormat(PredefinedFormat.DATE_MEDIUM));
+    // Set format that shows all fields and timezone of GMT-7
+    return new DateCell(DateTimeFormat.getFormat("dd-MM-yyyy HH:mm:ss"),
+        TimeZone.createTimeZone(7 * 60));
   }

   @Override
   @SuppressWarnings("deprecation")
   protected Date createCellValue() {
-    return new Date(2010 - 1900, 0, 1);
+    Date date = new Date();
+    date.setTime(3600 * 1000 * 10); // In GMT, Jan 1, 1970, 10:00:00
+    return date;
   }

   @Override
@@ -48,7 +52,7 @@

   @Override
   protected String getExpectedInnerHtml() {
-    return "Jan 1, 2010";
+    return "01-01-1970 03:00:00";  // 10 - 7 == 3
   }

   @Override

--
http://groups.google.com/group/Google-Web-Toolkit-Contributors

Reply via email to