Fix: test fails on phantomJs.
Change-Id: I70179c249a180a795e14683e4185068d5395762b
* @return
*/
public long getRangeInMinutesForDay(Date targetDay) {
+ long rangeInMinutesForDay = 0;
+ // we must take into account that here can be not only 1 and 2 days, but
+ // 1, 2, 3, 4... days first and last days - special cases all another
+ // days between first and last - have range "ALL DAY"
if (isTimeOnDifferentDays()) {
- // Time range is on different days. Calculate the second day's
- // range.
- long range = (getEndTime().getTime() - getEnd().getTime())
- / DateConstants.MINUTEINMILLIS;
-
- if (getEnd().compareTo(targetDay) != 0) {
- // Calculate first day's range.
- return getRangeInMinutes() - range;
+ if (targetDay.compareTo(getStart()) == 0) { // for first day
+ rangeInMinutesForDay = DateConstants.DAYINMINUTES
+ - (getStartTime().getTime() - getStart().getTime())
+ / DateConstants.MINUTEINMILLIS;
+ } else if (targetDay.compareTo(getEnd()) == 0) { // for last day
+ rangeInMinutesForDay = (getEndTime().getTime() - getEnd()
+ .getTime()) / DateConstants.MINUTEINMILLIS;
+ } else { // for in-between days
+ rangeInMinutesForDay = DateConstants.DAYINMINUTES;
}
-
- return range;
- } else {
- return getRangeInMinutes();
+ } else { // simple case - period is in one day
+ rangeInMinutesForDay = getRangeInMinutes();
}
+ return rangeInMinutesForDay;
}
/**
*/
@SuppressWarnings("deprecation")
public boolean isTimeOnDifferentDays() {
- if (getEndTime().getTime() - getStart().getTime() > DateConstants.DAYINMILLIS) {
- return true;
- }
-
- if (getStart().compareTo(getEnd()) != 0) {
- if (getEndTime().getHours() == 0 && getEndTime().getMinutes() == 0) {
- return false;
+ boolean isSeveralDays = false;
+
+ // if difference between start and end times is more than day - of
+ // course it is not one day, but several days
+ if (getEndTime().getTime() - getStartTime().getTime() > DateConstants.DAYINMILLIS) {
+ isSeveralDays = true;
+ } else { // if difference <= day -> there can be different cases
+ if (getStart().compareTo(getEnd()) != 0
+ && getEndTime().compareTo(getEnd()) != 0) {
+ isSeveralDays = true;
}
- return true;
}
- return false;
+ return isSeveralDays;
}
}
@SuppressWarnings("deprecation")
private void updatePositionFor(DateCellDayEvent dayEvent, Date targetDay,
CalendarEvent calendarEvent) {
- if (canDisplay(calendarEvent)) {
+ if (shouldDisplay(calendarEvent)) {
dayEvent.getElement().getStyle().clearDisplay();
Date fromDt = calendarEvent.getStartTime();
boolean onDifferentDays = calendarEvent.isTimeOnDifferentDays();
if (onDifferentDays) {
if (calendarEvent.getStart().compareTo(targetDay) != 0) {
- // Current day slot is for the end date. Lets fix also
- // the
- // start & end times.
+ // Current day slot is for the end date and all in-between
+ // days. Lets fix also the start & end times.
h = 0;
m = 0;
}
int startFromMinutes = (h * 60) + m;
dayEvent.updatePosition(startFromMinutes, range);
-
} else {
dayEvent.getElement().getStyle().setDisplay(Display.NONE);
}
*
* @param event
* @return
+ *
+ * This method is not necessary in the long run.. Or here can be
+ * various types of implementations..
*/
// Date methods not deprecated in GWT
@SuppressWarnings("deprecation")
- private boolean canDisplay(CalendarEvent event) {
- Date eventStart = event.getStartTime();
- Date eventEnd = event.getEndTime();
-
- int eventStartHours = eventStart.getHours();
- int eventEndHours = eventEnd.getHours();
-
- return (eventStartHours <= lastHour) && (eventEndHours >= firstHour);
+ private boolean shouldDisplay(CalendarEvent event) {
+ boolean display = true;
+ if (event.isTimeOnDifferentDays()) {
+ display = true;
+ } else { // only in case of one-day event we are able not to display
+ // event
+ // which is placed in unpublished parts on calendar
+ Date eventStart = event.getStartTime();
+ Date eventEnd = event.getEndTime();
+
+ int eventStartHours = eventStart.getHours();
+ int eventEndHours = eventEnd.getHours();
+
+ display = !(eventEndHours < firstHour || eventStartHours > lastHour);
+ }
+ return display;
}
@Override
import com.vaadin.client.DateTimeService;
import com.vaadin.client.Util;
import com.vaadin.client.ui.VCalendar;
+import com.vaadin.shared.ui.calendar.DateConstants;
/**
*
int pixelLength = 0;
int currentSlot = 0;
- int firstHourInMinutes = firstHour * 60;
+ int firstHourInMinutes = firstHour * DateConstants.HOURINMINUTES;
+ int endHourInMinutes = lastHour * DateConstants.HOURINMINUTES;
if (firstHourInMinutes > startFromMinutes) {
+ durationInMinutes = durationInMinutes
+ - (firstHourInMinutes - startFromMinutes);
startFromMinutes = 0;
} else {
startFromMinutes -= firstHourInMinutes;
}
+ int shownHeightInMinutes = endHourInMinutes - firstHourInMinutes
+ + DateConstants.HOURINMINUTES;
+
+ durationInMinutes = Math.min(durationInMinutes, shownHeightInMinutes
+ - startFromMinutes);
+
// calculate full slots to event
int slotsTillEvent = startFromMinutes / slotInMinutes;
int startOverFlowTime = slotInMinutes
public static final long DAYINMILLIS = 24 * HOURINMILLIS;
public static final long WEEKINMILLIS = 7 * DAYINMILLIS;
+ public static final int DAYINMINUTES = 24 * 60;
+ public static final int HOURINMINUTES = 60;
+
}
--- /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.calendar;
+
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+
+import com.vaadin.annotations.Theme;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Calendar;
+import com.vaadin.ui.Calendar.TimeFormat;
+import com.vaadin.ui.components.calendar.CalendarComponentEvents.EventResizeHandler;
+import com.vaadin.ui.components.calendar.event.BasicEvent;
+
+/**
+ *
+ * @since
+ * @author Vaadin Ltd
+ *
+ * test for defect: calendar visible hours of day invalid shows invalid
+ * dates(week/day view) (#12521)
+ */
+@Theme("tests-calendar")
+public class CalendarVisibleHours extends AbstractTestUI {
+
+ private static final long serialVersionUID = 1L;
+ private Calendar calendar;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#setup(com.vaadin.server.
+ * VaadinRequest)
+ */
+ @Override
+ protected void setup(VaadinRequest request) {
+ calendar = new Calendar();
+
+ try {
+
+ BasicEvent event = new BasicEvent("EVENT NAME 1",
+ "EVENT TOOLTIP 1",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm")
+ .parse("2013-09-05 15:30"), new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm").parse("2013-09-07 22:20"));
+ event.setStyleName("color1");
+ calendar.addEvent(event);
+
+ event = new BasicEvent("EVENT NAME 2", "EVENT TOOLTIP 2",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm")
+ .parse("2013-09-05 12:10"), new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm").parse("2013-09-05 13:20"));
+ event.setStyleName("color2");
+ calendar.addEvent(event);
+
+ event = new BasicEvent("EVENT NAME 3", "EVENT TOOLTIP 3",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm")
+ .parse("2013-09-01 11:30"), new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm").parse("2013-09-29 15:20"));
+ event.setStyleName("color3");
+ calendar.addEvent(event);
+
+ event = new BasicEvent("EVENT NAME 4", "EVENT TOOLTIP 4",
+ new SimpleDateFormat("yyyy-MM-dd HH:mm")
+ .parse("2013-09-01 11:30"), new SimpleDateFormat(
+ "yyyy-MM-dd HH:mm").parse("2013-09-01 15:20"));
+ event.setStyleName("color4");
+ event.setAllDay(true);
+ calendar.addEvent(event);
+ } catch (ParseException e1) { // Nothing to do
+ e1.printStackTrace();
+ }
+
+ try {
+ calendar.setStartDate(new SimpleDateFormat("yyyy-MM-dd")
+ .parse("2013-09-01"));
+ calendar.setEndDate(new SimpleDateFormat("yyyy-MM-dd")
+ .parse("2013-09-30"));
+ } catch (ParseException e) { // Nothing to do
+
+ }
+
+ calendar.setImmediate(true);
+
+ calendar.setFirstVisibleHourOfDay(8);
+ calendar.setLastVisibleHourOfDay(16);
+
+ calendar.setTimeFormat(TimeFormat.Format24H);
+ calendar.setHandler((EventResizeHandler) null);
+ setEnabled(true);
+
+ addComponent(calendar);
+ calendar.setSizeFull();
+ setSizeFull();
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTestDescription()
+ */
+ @Override
+ protected String getTestDescription() {
+ return "Validate fix of defect 'Calendar visible hours of day invalid shows invalid dates(week/day view)'";
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.tests.components.AbstractTestUI#getTicketNumber()
+ */
+ @Override
+ protected Integer getTicketNumber() {
+ return 12521;
+ }
+
+}
--- /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.calendar;
+
+import java.io.IOException;
+import java.util.List;
+
+import org.junit.Test;
+import org.openqa.selenium.By;
+import org.openqa.selenium.WebElement;
+
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Tests calendar via prepared screenshots calendar visible hours of day invalid
+ * shows invalid dates(week/day view) (#12521)
+ */
+public class CalendarVisibleHoursTest extends MultiBrowserTest {
+
+ @Test
+ public void testCalendar() throws InterruptedException, IOException {
+ openTestURL();
+
+ openWeekView();
+ compareScreen("weekview");
+
+ openDayView();
+
+ compareScreen("dayview");
+ }
+
+ private void openWeekView() {
+ List<WebElement> elements = getDriver().findElements(
+ By.className("v-calendar-week-number"));
+
+ for (WebElement webElement : elements) {
+ if (webElement.getText().equals("36")) {
+ webElement.click();
+ break;
+ }
+ }
+ }
+
+ private void openDayView() {
+ List<WebElement> elements = getDriver().findElements(
+ By.className("v-calendar-header-day"));
+
+ for (WebElement webElement : elements) {
+ if (webElement.getText().contains("Thursday 9/5/13")) {
+ webElement.click();
+ break;
+ }
+ }
+ }
+}