throw new IllegalStateException(
"startDate cannot be later than endDate");
}
- getState().rangeStart = startDate;
- // rangeStart = startDate;
- // This has to be done to correct for the resolution
- // updateRangeState();
+
+ // Create a defensive copy against issues when using java.sql.Date (and
+ // also against mutable Date).
+ getState().rangeStart = new Date(startDate.getTime());
updateRangeValidator();
}
throw new IllegalStateException(
"endDate cannot be earlier than startDate");
}
- // rangeEnd = endDate;
- getState().rangeEnd = endDate;
+
+ // Create a defensive copy against issues when using java.sql.Date (and
+ // also against mutable Date).
+ getState().rangeEnd = new Date(endDate.getTime());
updateRangeValidator();
}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.datefield;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.DateField;
+import com.vaadin.ui.InlineDateField;
+
+public class DateRangeWithSqlDate extends AbstractTestUI {
+
+ // 2014-12-01
+ private static final java.sql.Date startDate = new java.sql.Date(
+ 1417467822699L);
+
+ // 2014-12-02
+ private static final java.sql.Date endDate = new java.sql.Date(
+ 1417554763317L);
+
+ @Override
+ protected void setup(VaadinRequest request) {
+ DateField df = new InlineDateField();
+ df.setRangeStart(startDate);
+ df.setRangeEnd(endDate);
+
+ df.setValue(startDate);
+
+ addComponent(df);
+ }
+
+ @Override
+ protected String getTestDescription() {
+ return "Test that java.sql.Date can be given to specify date range start and end dates.";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 15342;
+ }
+
+}
--- /dev/null
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.datefield;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+public class DateRangeWithSqlDateTest extends MultiBrowserTest {
+
+ @Test
+ public void testDateRange() {
+ openTestURL();
+
+ // Get all cells of the inline datefield.
+ List<WebElement> cells = driver.findElements(By
+ .className("v-inline-datefield-calendarpanel-day"));
+
+ // Verify the range is rendered correctly.
+ assertCell(cells.get(0), "30", true);
+ assertCell(cells.get(1), "1", false);
+ assertCell(cells.get(2), "2", false);
+ assertCell(cells.get(3), "3", true);
+ }
+
+ private void assertCell(WebElement cell, String text, boolean outsideRange) {
+ assertEquals(text, cell.getText());
+ assertEquals(outsideRange,
+ cell.getAttribute("class").contains("outside-range"));
+ }
+
+}