1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Leading and trailing days should be considered part of the month in month view.

Summary: Closes T8177, Leading and trailing days should be considered part of the month in month view.

Test Plan: Open month view, no days should be empty unless they don't have events. Modify query, make sure month view still obeys query.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T8177

Differential Revision: https://secure.phabricator.com/D12834
This commit is contained in:
lkassianik 2015-05-13 19:02:33 -07:00
parent 97611958b0
commit a76d3a8bb5
2 changed files with 55 additions and 13 deletions

View file

@ -76,11 +76,33 @@ final class PhabricatorCalendarEventSearchEngine
$display_start = $start_day->format('U');
$display_end = $next->format('U');
// 0 = Sunday is always the start of the week, for now
$start_of_week = 0;
$end_of_week = 6 - $start_of_week;
$first_of_month = $start_day->format('w');
$last_of_month = id(clone $next)->modify('-1 day')->format('w');
if (!$min_range || ($min_range < $display_start)) {
$min_range = $display_start;
if ($this->isMonthView($saved) &&
$first_of_month > $start_of_week) {
$min_range = id(clone $start_day)
->modify('-'.$first_of_month.' days')
->format('U');
}
}
if (!$max_range || ($max_range > $display_end)) {
$max_range = $display_end;
if ($this->isMonthView($saved) &&
$last_of_month < $end_of_week) {
$max_range = id(clone $next)
->modify('+'.(6 - $first_of_month).' days')
->format('U');
}
}
}

View file

@ -56,14 +56,8 @@ final class PHUICalendarMonthView extends AphrontView {
}
$events = msort($this->events, 'getEpochStart');
$days = $this->getDatesInMonth();
require_celerity_resource('phui-calendar-month-css');
$first = reset($days);
$empty = $first->format('w');
$cell_lists = array();
$empty_cell = array(
'list' => null,
@ -73,6 +67,13 @@ final class PHUICalendarMonthView extends AphrontView {
'class' => null,
);
require_celerity_resource('phui-calendar-month-css');
$first = reset($days);
$start_of_week = 0;
$empty = $first->format('w');
for ($ii = 0; $ii < $empty; $ii++) {
$cell_lists[] = $empty_cell;
}
@ -409,22 +410,41 @@ final class PHUICalendarMonthView extends AphrontView {
$month = $this->month;
$year = $this->year;
// Get the year and month numbers of the following month, so we can
// determine when this month ends.
list($next_year, $next_month) = $this->getNextYearAndMonth();
$end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone);
$end_epoch = $end_date->format('U');
$start_of_week = 0;
$end_of_week = 6 - $start_of_week;
$days_in_month = id(clone $end_date)->modify('-1 day')->format('d');
$first_month_day_date = new DateTime("{$year}-{$month}-01", $timezone);
$last_month_day_date = id(clone $end_date)->modify('-1 day');
$first_weekday_of_month = $first_month_day_date->format('w');
$last_weekday_of_month = $last_month_day_date->format('w');
$num_days_display = $days_in_month;
if ($start_of_week < $first_weekday_of_month) {
$num_days_display += $first_weekday_of_month;
}
if ($end_of_week > $last_weekday_of_month) {
$num_days_display += (6 - $last_weekday_of_month);
$end_date->modify('+'.(6 - $last_weekday_of_month).' days');
}
$days = array();
for ($day = 1; $day <= 31; $day++) {
$day_date = new DateTime("{$year}-{$month}-{$day}", $timezone);
$day_date = id(clone $first_month_day_date)
->modify('-'.$first_weekday_of_month.' days');
for ($day = 1; $day <= $num_days_display; $day++) {
$day_epoch = $day_date->format('U');
$end_epoch = $end_date->format('U');
if ($day_epoch >= $end_epoch) {
break;
} else {
$days[] = $day_date;
$days[] = clone $day_date;
}
$day_date->modify('+1 day');
}
return $days;