// 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;
}
--- /dev/null
+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;
+ }
+}
--- /dev/null
+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