summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSauli Tähkäpää <sauli@vaadin.com>2014-09-14 01:01:21 +0300
committerMarkus Koivisto <markus@vaadin.com>2014-10-14 17:58:51 +0300
commitb6e66dd76ec744b5e779905060eeaa29783352d2 (patch)
tree7d0acb0d1edf319303e57ca793b6e62de4ab4bd2
parentc3bf85412214d56bbbaf19a04ff1b7012e6428f6 (diff)
downloadvaadin-framework-b6e66dd76ec744b5e779905060eeaa29783352d2.tar.gz
vaadin-framework-b6e66dd76ec744b5e779905060eeaa29783352d2.zip
Assign timezone before setting initial date in DateField. (#14653)
Change-Id: I3b527084d23ee8bd49887bef3d018c1003f492e2
-rw-r--r--server/src/com/vaadin/ui/DateField.java10
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java68
-rw-r--r--uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java43
3 files changed, 115 insertions, 6 deletions
diff --git a/server/src/com/vaadin/ui/DateField.java b/server/src/com/vaadin/ui/DateField.java
index e88d767bc9..030bd5f6c2 100644
--- a/server/src/com/vaadin/ui/DateField.java
+++ b/server/src/com/vaadin/ui/DateField.java
@@ -815,17 +815,15 @@ public class DateField extends AbstractField<Date> implements
// Clone the instance
final Calendar newCal = (Calendar) calendar.clone();
- // Assigns the current time tom calendar.
- final Date currentDate = getValue();
- if (currentDate != null) {
- newCal.setTime(currentDate);
- }
-
final TimeZone currentTimeZone = getTimeZone();
if (currentTimeZone != null) {
newCal.setTimeZone(currentTimeZone);
}
+ final Date currentDate = getValue();
+ if (currentDate != null) {
+ newCal.setTime(currentDate);
+ }
return newCal;
}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java
new file mode 100644
index 0000000000..62db60be76
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffset.java
@@ -0,0 +1,68 @@
+package com.vaadin.tests.components.datefield;
+
+import com.vaadin.data.Property;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.datefield.Resolution;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.Label;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+public class DateFieldDayResolutionOffset extends AbstractTestUI {
+
+ private final String initialDateString = "09/01/2014 00:00:00";
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ final Label dateValue = new Label(initialDateString);
+ dateValue.setId("dateValue");
+
+ final TimeZone timezone = TimeZone.getTimeZone("GMT");
+ final SimpleDateFormat dateformat = getDateFormat(timezone);
+ final DateField dateField = getDateField(timezone, dateformat);
+
+ addComponent(dateValue);
+ addComponent(dateField);
+
+ dateField.addValueChangeListener( new Property.ValueChangeListener(){
+ @Override
+ public void valueChange(Property.ValueChangeEvent event) {
+ dateValue.setValue(dateformat.format(dateField.getValue()));
+ }
+ });
+ }
+
+ private DateField getDateField(TimeZone timezone, SimpleDateFormat dateformat) {
+ final DateField dateField = new DateField();
+ try {
+ Date initialDate = dateformat.parse(initialDateString);
+ dateField.setResolution(Resolution.DAY);
+ dateField.setTimeZone(timezone);
+ dateField.setValue(initialDate);
+ } catch (ParseException e) {
+ e.printStackTrace();
+ }
+ return dateField;
+ }
+
+ private SimpleDateFormat getDateFormat(TimeZone timezone) {
+ final SimpleDateFormat dateformat = new SimpleDateFormat("MM/dd/yyyy HH:mm:ss");
+ dateformat.setTimeZone(timezone);
+ return dateformat;
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "The time should stay at 00:00:00 when selecting dates with Resolution.DAY selected.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 14653;
+ }
+}
diff --git a/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java
new file mode 100644
index 0000000000..c3b3af9aa4
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/datefield/DateFieldDayResolutionOffsetTest.java
@@ -0,0 +1,43 @@
+package com.vaadin.tests.components.datefield;
+
+import com.vaadin.testbench.elements.DateFieldElement;
+import com.vaadin.testbench.elements.LabelElement;
+import com.vaadin.tests.tb3.AbstractTB3Test;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.core.Is.is;
+
+public class DateFieldDayResolutionOffsetTest extends MultiBrowserTest {
+
+ @Test
+ public void dateValueDoesNotHaveOffset() throws InterruptedException {
+ openTestURL();
+
+ openDatePicker();
+ select2ndOfSeptember();
+
+ LabelElement dateValue = $(LabelElement.class).id("dateValue");
+ assertThat(dateValue.getText(), is("09/02/2014 00:00:00"));
+ }
+
+ private void select2ndOfSeptember() {
+ for(WebElement e : findElements(By.className("v-datefield-calendarpanel-day"))) {
+ if(e.getText().equals("2")) {
+ e.click();
+ break;
+ }
+ }
+ }
+
+ private void openDatePicker() {
+ DateFieldElement dateField = $(DateFieldElement.class).first();
+
+ dateField.findElement(By.tagName("button"))
+ .click();
+ }
+
+} \ No newline at end of file