mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-21 04:50:55 +01:00
Refactor logic for getting next/prev month and day on month and day views, respectively
Summary: Ref T4393, Refactor logic for getting next/prev month and day on month and day views, respectively Test Plan: Open Calendar search, search using month view, scroll next/prev months to observe correct navigation, repeat with day view. Reviewers: #blessed_reviewers, epriestley Reviewed By: #blessed_reviewers, epriestley Subscribers: Korvin, epriestley Maniphest Tasks: T4393 Differential Revision: https://secure.phabricator.com/D12723
This commit is contained in:
parent
336ccfeea1
commit
7e4d5f76c0
2 changed files with 37 additions and 103 deletions
|
@ -253,95 +253,28 @@ final class PHUICalendarDayView extends AphrontView {
|
||||||
return $included_datetimes;
|
return $included_datetimes;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNumberOfDaysInMonth($month, $year) {
|
|
||||||
$user = $this->user;
|
|
||||||
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
|
||||||
|
|
||||||
list($next_year, $next_month) = $this->getNextYearAndMonth($month, $year);
|
|
||||||
|
|
||||||
$end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone);
|
|
||||||
$end_epoch = $end_date->format('U');
|
|
||||||
|
|
||||||
$days = 0;
|
|
||||||
for ($day = 1; $day <= 31; $day++) {
|
|
||||||
$day_date = new DateTime("{$year}-{$month}-{$day}", $timezone);
|
|
||||||
$day_epoch = $day_date->format('U');
|
|
||||||
if ($day_epoch >= $end_epoch) {
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
$days++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $days;
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getPrevDay() {
|
private function getPrevDay() {
|
||||||
$day = $this->day;
|
$prev = $this->getDateTime();
|
||||||
$month = $this->month;
|
$prev->modify('-1 day');
|
||||||
$year = $this->year;
|
return array(
|
||||||
|
$prev->format('Y'),
|
||||||
$prev_year = $year;
|
$prev->format('m'),
|
||||||
$prev_month = $month;
|
$prev->format('d'),
|
||||||
$prev_day = $day - 1;
|
);
|
||||||
if ($prev_day == 0) {
|
|
||||||
$prev_month--;
|
|
||||||
if ($prev_month == 0) {
|
|
||||||
$prev_year--;
|
|
||||||
$prev_month = 12;
|
|
||||||
}
|
|
||||||
$prev_day = $this->getNumberOfDaysInMonth($prev_month, $prev_year);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($prev_year, $prev_month, $prev_day);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNextDay() {
|
private function getNextDay() {
|
||||||
$day = $this->day;
|
$next = $this->getDateTime();
|
||||||
$month = $this->month;
|
$next->modify('+1 day');
|
||||||
$year = $this->year;
|
return array(
|
||||||
|
$next->format('Y'),
|
||||||
$next_year = $year;
|
$next->format('m'),
|
||||||
$next_month = $month;
|
$next->format('d'),
|
||||||
$next_day = $day + 1;
|
);
|
||||||
$days_in_month = $this->getNumberOfDaysInMonth($month, $year);
|
|
||||||
if ($next_day > $days_in_month) {
|
|
||||||
$next_day = 1;
|
|
||||||
$next_month++;
|
|
||||||
}
|
|
||||||
if ($next_month == 13) {
|
|
||||||
$next_year++;
|
|
||||||
$next_month = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($next_year, $next_month, $next_day);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getNextYearAndMonth($month, $year) {
|
|
||||||
$next_year = $year;
|
|
||||||
$next_month = $month + 1;
|
|
||||||
if ($next_month == 13) {
|
|
||||||
$next_year = $year + 1;
|
|
||||||
$next_month = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($next_year, $next_month);
|
|
||||||
}
|
|
||||||
|
|
||||||
private function getPrevYearAndMonth($month, $year) {
|
|
||||||
$prev_year = $year;
|
|
||||||
$prev_month = $month - 1;
|
|
||||||
if ($prev_month == 0) {
|
|
||||||
$prev_year = $year - 1;
|
|
||||||
$prev_month = 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($prev_year, $prev_month);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getDateTime() {
|
private function getDateTime() {
|
||||||
$user = $this->user;
|
$user = $this->user;
|
||||||
|
|
||||||
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
||||||
|
|
||||||
$day = $this->day;
|
$day = $this->day;
|
||||||
|
|
|
@ -251,31 +251,21 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getNextYearAndMonth() {
|
private function getNextYearAndMonth() {
|
||||||
$month = $this->month;
|
$next = $this->getDateTime();
|
||||||
$year = $this->year;
|
$next->modify('+1 month');
|
||||||
|
return array(
|
||||||
$next_year = $year;
|
$next->format('Y'),
|
||||||
$next_month = $month + 1;
|
$next->format('m'),
|
||||||
if ($next_month == 13) {
|
);
|
||||||
$next_year = $year + 1;
|
|
||||||
$next_month = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($next_year, $next_month);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function getPrevYearAndMonth() {
|
private function getPrevYearAndMonth() {
|
||||||
$month = $this->month;
|
$prev = $this->getDateTime();
|
||||||
$year = $this->year;
|
$prev->modify('-1 month');
|
||||||
|
return array(
|
||||||
$prev_year = $year;
|
$prev->format('Y'),
|
||||||
$prev_month = $month - 1;
|
$prev->format('m'),
|
||||||
if ($prev_month == 0) {
|
);
|
||||||
$prev_year = $year - 1;
|
|
||||||
$prev_month = 12;
|
|
||||||
}
|
|
||||||
|
|
||||||
return array($prev_year, $prev_month);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -313,4 +303,15 @@ final class PHUICalendarMonthView extends AphrontView {
|
||||||
return $days;
|
return $days;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function getDateTime() {
|
||||||
|
$user = $this->user;
|
||||||
|
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
|
||||||
|
|
||||||
|
$month = $this->month;
|
||||||
|
$year = $this->year;
|
||||||
|
|
||||||
|
$date = new DateTime("{$year}-{$month}-01 ", $timezone);
|
||||||
|
|
||||||
|
return $date;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue