Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14064331
D12723.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
4 KB
Referenced Files
None
Subscribers
None
D12723.diff
View Options
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
@@ -253,95 +253,28 @@
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() {
- $day = $this->day;
- $month = $this->month;
- $year = $this->year;
-
- $prev_year = $year;
- $prev_month = $month;
- $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);
+ $prev = $this->getDateTime();
+ $prev->modify('-1 day');
+ return array(
+ $prev->format('Y'),
+ $prev->format('m'),
+ $prev->format('d'),
+ );
}
private function getNextDay() {
- $day = $this->day;
- $month = $this->month;
- $year = $this->year;
-
- $next_year = $year;
- $next_month = $month;
- $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);
+ $next = $this->getDateTime();
+ $next->modify('+1 day');
+ return array(
+ $next->format('Y'),
+ $next->format('m'),
+ $next->format('d'),
+ );
}
private function getDateTime() {
$user = $this->user;
-
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$day = $this->day;
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
@@ -251,31 +251,21 @@
}
private function getNextYearAndMonth() {
- $month = $this->month;
- $year = $this->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);
+ $next = $this->getDateTime();
+ $next->modify('+1 month');
+ return array(
+ $next->format('Y'),
+ $next->format('m'),
+ );
}
private function getPrevYearAndMonth() {
- $month = $this->month;
- $year = $this->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);
+ $prev = $this->getDateTime();
+ $prev->modify('-1 month');
+ return array(
+ $prev->format('Y'),
+ $prev->format('m'),
+ );
}
/**
@@ -313,4 +303,15 @@
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;
+ }
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Nov 19, 10:59 PM (16 h, 13 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6770371
Default Alt Text
D12723.diff (4 KB)
Attached To
Mode
D12723: Refactor logic for getting next/prev month and day on month and day views, respectively
Attached
Detach File
Event Timeline
Log In to Comment