From: Matti Tahvonen Date: Thu, 17 Apr 2008 14:33:21 +0000 (+0000) Subject: Fixed nasty bug with CalendarField component (used in Reservr). It worked correctly... X-Git-Tag: 6.7.0.beta1~4883 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c575ac8a5f1476a2eb678a347652ca4745149ccf;p=vaadin-framework.git Fixed nasty bug with CalendarField component (used in Reservr). It worked correctly only if server and client had same timezone. Had to fight with this too long while playing around with liferay... svn changeset:4192/svn branch:trunk --- diff --git a/src/com/itmill/toolkit/demo/reservation/CalendarField.java b/src/com/itmill/toolkit/demo/reservation/CalendarField.java index 565d78a97b..b28ae4df1d 100644 --- a/src/com/itmill/toolkit/demo/reservation/CalendarField.java +++ b/src/com/itmill/toolkit/demo/reservation/CalendarField.java @@ -4,6 +4,7 @@ package com.itmill.toolkit.demo.reservation; +import java.text.SimpleDateFormat; import java.util.Collection; import java.util.Date; import java.util.Iterator; @@ -68,7 +69,7 @@ public class CalendarField extends DateField implements Container.Viewer { public void init() { super.setResolution(RESOLUTION_HOUR); - + } /** @@ -282,15 +283,22 @@ public class CalendarField extends DateField implements Container.Viewer { final String styleName = (String) p.getValue(); target.addAttribute("styleName", styleName); } - target.addAttribute("start", "" + start.getTime()); + SimpleDateFormat sdf = new SimpleDateFormat( + "d MMM yyyy HH:mm:ss Z"); + + target.addAttribute("Z", start.getTimezoneOffset()); + + target.addAttribute("start", "" + sdf.format(start)); + if (end != start) { - target.addAttribute("end", "" + end.getTime()); + target.addAttribute("end", "" + sdf.format(end)); } if (itemTitlePropertyId != null) { p = item.getItemProperty(itemTitlePropertyId); final Object val = p.getValue(); if (val != null) { target.addAttribute("title", val.toString()); + System.out.println(val); } } if (itemDescriptionPropertyId != null) { diff --git a/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendarField.java b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendarField.java index 70aaf642de..2016b53e0f 100644 --- a/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendarField.java +++ b/src/com/itmill/toolkit/demo/reservation/gwt/client/ui/ICalendarField.java @@ -10,6 +10,7 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; +import com.google.gwt.i18n.client.DateTimeFormat; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.Element; import com.google.gwt.user.client.ui.FlexTable; @@ -194,9 +195,10 @@ public class ICalendarField extends IDateField { } - private native void setScrollTop(Element el, int scrollTop) /*-{ - el.scrollTop = scrollTop; - }-*/; + private native void setScrollTop(Element el, int scrollTop) + /*-{ + el.scrollTop = scrollTop; + }-*/; private class HourTableListener implements TableListener { @@ -217,16 +219,23 @@ public class ICalendarField extends IDateField { public void addItem(UIDL item) { final String styleName = item.getStringAttribute("styleName"); // final Integer id = new Integer(item.getIntAttribute("id")); - final long start = Long.parseLong(item.getStringAttribute("start")); - final Date startDate = new Date(start); - long end = -1; - try { - end = Long.parseLong(item.getStringAttribute("end")); - } catch (final Exception IGNORED) { - // IGNORED attribute not required + + DateTimeFormat dtf = DateTimeFormat + .getFormat("d MMM yyyy HH:mm:ss Z"); + + Date startDate = dtf.parse(item.getStringAttribute("start")); + + // fix times with server-client difference + int diff = (startDate.getTimezoneOffset() - item + .getIntAttribute("Z")) * 60000; + startDate = new Date(startDate.getTime() + diff); + Date endDate; + if (item.hasAttribute("end")) { + endDate = dtf.parse(item.getStringAttribute("end")); + endDate = new Date(endDate.getTime() + diff); + } else { + endDate = (Date) startDate.clone(); } - final Date endDate = (end > 0 && end != start ? new Date(end) - : new Date(start)); final String title = item.getStringAttribute("title"); final String desc = item.getStringAttribute("description"); final boolean notime = item.getBooleanAttribute("notime");