summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>2014-09-04 13:32:35 +0400
committerSauli Tähkäpää <sauli@vaadin.com>2014-09-12 16:27:40 +0300
commitacec953fd47b63b1a7ea411d8680ba0b921f2b0f (patch)
tree0568ca60a46422bfe09272e5644c27d235ad2398 /client
parentef79ed198865410618320bbf3af1e691cac32760 (diff)
downloadvaadin-framework-acec953fd47b63b1a7ea411d8680ba0b921f2b0f.tar.gz
vaadin-framework-acec953fd47b63b1a7ea411d8680ba0b921f2b0f.zip
calendar visible hours shows invalid dates(week/day view) (#12521)
Fix: test fails on phantomJs. Change-Id: I70179c249a180a795e14683e4185068d5395762b
Diffstat (limited to 'client')
-rw-r--r--client/src/com/vaadin/client/ui/calendar/schedule/CalendarEvent.java48
-rw-r--r--client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java35
-rw-r--r--client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java12
3 files changed, 60 insertions, 35 deletions
diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/CalendarEvent.java b/client/src/com/vaadin/client/ui/calendar/schedule/CalendarEvent.java
index d3a5e3f16e..5630db2415 100644
--- a/client/src/com/vaadin/client/ui/calendar/schedule/CalendarEvent.java
+++ b/client/src/com/vaadin/client/ui/calendar/schedule/CalendarEvent.java
@@ -274,21 +274,25 @@ public class CalendarEvent {
* @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;
}
/**
@@ -298,16 +302,18 @@ public class CalendarEvent {
*/
@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;
}
}
diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java b/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java
index ffa5f78071..9e110b6d7a 100644
--- a/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java
+++ b/client/src/com/vaadin/client/ui/calendar/schedule/DateCell.java
@@ -510,8 +510,8 @@ public class DateCell extends FocusableComplexPanel implements
@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();
@@ -522,9 +522,8 @@ public class DateCell extends FocusableComplexPanel implements
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;
}
@@ -532,7 +531,6 @@ public class DateCell extends FocusableComplexPanel implements
int startFromMinutes = (h * 60) + m;
dayEvent.updatePosition(startFromMinutes, range);
-
} else {
dayEvent.getElement().getStyle().setDisplay(Display.NONE);
}
@@ -571,17 +569,28 @@ public class DateCell extends FocusableComplexPanel implements
*
* @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
diff --git a/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java b/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java
index d1d99e6cf2..545ddadc52 100644
--- a/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java
+++ b/client/src/com/vaadin/client/ui/calendar/schedule/WeekGrid.java
@@ -33,6 +33,7 @@ import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.DateTimeService;
import com.vaadin.client.Util;
import com.vaadin.client.ui.VCalendar;
+import com.vaadin.shared.ui.calendar.DateConstants;
/**
*
@@ -307,14 +308,23 @@ public class WeekGrid extends SimplePanel {
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