diff --git a/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php b/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php --- a/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php @@ -323,11 +323,15 @@ if ($start_month == $now_month && $start_year == $now_year) { $month_view = new PHUICalendarMonthView( + $this->getDateFrom($query), + $this->getDateTo($query), $start_month, $start_year, $now_day); } else { $month_view = new PHUICalendarMonthView( + $this->getDateFrom($query), + $this->getDateTo($query), $start_month, $start_year); } diff --git a/src/view/phui/calendar/PHUICalendarDayView.php b/src/view/phui/calendar/PHUICalendarDayView.php --- a/src/view/phui/calendar/PHUICalendarDayView.php +++ b/src/view/phui/calendar/PHUICalendarDayView.php @@ -170,33 +170,13 @@ $header = $this->renderDayViewHeader(); $sidebar = $this->renderSidebar(); - - $errors = array(); - - $range_start_epoch = $this->rangeStart->getEpoch(); - $range_end_epoch = $this->rangeEnd->getEpoch(); - - if (($range_start_epoch != null && - $range_start_epoch < $day_end && - $range_start_epoch > $day_start) || - ($range_end_epoch != null && - $range_end_epoch < $day_end && - $range_end_epoch > $day_start)) { - $errors[] = pht('Part of the day is out of range'); - } - - if (($this->rangeEnd->getEpoch() != null && - $this->rangeEnd->getEpoch() < $day_start) || - ($this->rangeStart->getEpoch() != null && - $this->rangeStart->getEpoch() > $day_end)) { - $errors[] = pht('Day is out of query range'); - } + $warnings = $this->getQueryRangeWarning(); $table_box = id(new PHUIObjectBoxView()) ->setHeader($header) ->appendChild($all_day_event_box) ->appendChild($table) - ->setFormErrors($errors) + ->setFormErrors($warnings) ->setFlush(true); $layout = id(new AphrontMultiColumnView()) @@ -226,6 +206,35 @@ return $all_day_events; } + private function getQueryRangeWarning() { + $errors = array(); + + $range_start_epoch = $this->rangeStart->getEpoch(); + $range_end_epoch = $this->rangeEnd->getEpoch(); + + $day_start = $this->getDateTime(); + $day_end = id(clone $day_start)->modify('+1 day'); + + $day_start = $day_start->format('U'); + $day_end = $day_end->format('U') - 1; + + if (($range_start_epoch != null && + $range_start_epoch < $day_end && + $range_start_epoch > $day_start) || + ($range_end_epoch != null && + $range_end_epoch < $day_end && + $range_end_epoch > $day_start)) { + $errors[] = pht('Part of the day is out of range'); + } + + if (($this->rangeEnd->getEpoch() != null && + $this->rangeEnd->getEpoch() < $day_start) || + ($this->rangeStart->getEpoch() != null && + $this->rangeStart->getEpoch() > $day_end)) { + $errors[] = pht('Day is out of query range'); + } + } + private function renderSidebar() { $this->events = msort($this->events, 'getEpochStart'); $week_of_boxes = $this->getWeekOfBoxes(); diff --git a/src/view/phui/calendar/PHUICalendarMonthView.php b/src/view/phui/calendar/PHUICalendarMonthView.php --- a/src/view/phui/calendar/PHUICalendarMonthView.php +++ b/src/view/phui/calendar/PHUICalendarMonthView.php @@ -1,6 +1,8 @@ rangeStart = $range_start; + $this->rangeEnd = $range_end; + $this->day = $day; $this->month = $month; $this->year = $year; @@ -188,9 +199,12 @@ phutil_implode_html("\n", $table), )); + $warnings = $this->getQueryRangeWarning(); + $box = id(new PHUIObjectBoxView()) ->setHeader($this->renderCalendarHeader($first)) - ->appendChild($table); + ->appendChild($table) + ->setFormErrors($warnings); if ($this->error) { $box->setInfoView($this->error); @@ -250,6 +264,37 @@ return $header; } + private function getQueryRangeWarning() { + $errors = array(); + + $range_start_epoch = $this->rangeStart->getEpoch(); + $range_end_epoch = $this->rangeEnd->getEpoch(); + + $month_start = $this->getDateTime(); + $month_end = id(clone $month_start)->modify('+1 month'); + + $month_start = $month_start->format('U'); + $month_end = $month_end->format('U') - 1; + + if (($range_start_epoch != null && + $range_start_epoch < $month_end && + $range_start_epoch > $month_start) || + ($range_end_epoch != null && + $range_end_epoch < $month_end && + $range_end_epoch > $month_start)) { + $errors[] = pht('Part of the month is out of range'); + } + + if (($this->rangeEnd->getEpoch() != null && + $this->rangeEnd->getEpoch() < $month_start) || + ($this->rangeStart->getEpoch() != null && + $this->rangeStart->getEpoch() > $month_end)) { + $errors[] = pht('Month is out of query range'); + } + + return $errors; + } + private function getNextYearAndMonth() { $next = $this->getDateTime(); $next->modify('+1 month');