@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add a setting so user can choose when Calendar weeks start

Summary: Closes T8176, Add a setting so user can choose when Calendar weeks start

Test Plan: Open account settings, go to "Date and Time", change week start day, open Calendar, observe that month view responds to new week start day.

Reviewers: #blessed_reviewers, epriestley

Reviewed By: #blessed_reviewers, epriestley

Subscribers: Korvin, epriestley

Maniphest Tasks: T8176

Differential Revision: https://secure.phabricator.com/D12884

+82 -47
+11 -7
src/applications/calendar/query/PhabricatorCalendarEventSearchEngine.php
··· 76 76 $display_start = $start_day->format('U'); 77 77 $display_end = $next->format('U'); 78 78 79 - // 0 = Sunday is always the start of the week, for now 80 - $start_of_week = 0; 81 - $end_of_week = 6 - $start_of_week; 79 + $preferences = $viewer->loadPreferences(); 80 + $pref_week_day = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; 81 + 82 + $start_of_week = $preferences->getPreference($pref_week_day, 0); 83 + $end_of_week = ($start_of_week + 6) % 7; 82 84 83 85 $first_of_month = $start_day->format('w'); 84 86 $last_of_month = id(clone $next)->modify('-1 day')->format('w'); ··· 87 89 $min_range = $display_start; 88 90 89 91 if ($this->isMonthView($saved) && 90 - $first_of_month > $start_of_week) { 92 + $first_of_month !== $start_of_week) { 93 + $interim_day_num = ($first_of_month + 7 - $start_of_week) % 7; 91 94 $min_range = id(clone $start_day) 92 - ->modify('-'.$first_of_month.' days') 95 + ->modify('-'.$interim_day_num.' days') 93 96 ->format('U'); 94 97 } 95 98 } ··· 97 100 $max_range = $display_end; 98 101 99 102 if ($this->isMonthView($saved) && 100 - $last_of_month < $end_of_week) { 103 + $last_of_month !== $end_of_week) { 104 + $interim_day_num = ($end_of_week + 7 - $last_of_month) % 7; 101 105 $max_range = id(clone $next) 102 - ->modify('+'.(6 - $first_of_month).' days') 106 + ->modify('+'.$interim_day_num.' days') 103 107 ->format('U'); 104 108 } 105 109
+27 -1
src/applications/settings/panel/PhabricatorDateTimeSettingsPanel.php
··· 19 19 $username = $user->getUsername(); 20 20 21 21 $pref_time = PhabricatorUserPreferences::PREFERENCE_TIME_FORMAT; 22 + $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; 22 23 $preferences = $user->loadPreferences(); 23 24 24 25 $errors = array(); ··· 30 31 $errors[] = pht('The selected timezone is not a valid timezone.'); 31 32 } 32 33 33 - $preferences->setPreference($pref_time, $request->getStr($pref_time)); 34 + $preferences->setPreference( 35 + $pref_time, 36 + $request->getStr($pref_time)); 37 + $preferences->setPreference( 38 + $pref_week_start, 39 + $request->getStr($pref_week_start)); 34 40 35 41 if (!$errors) { 36 42 $preferences->save(); ··· 73 79 pht('Format used when rendering a time of day.')) 74 80 ->setValue($preferences->getPreference($pref_time))) 75 81 ->appendChild( 82 + id(new AphrontFormSelectControl()) 83 + ->setLabel(pht('Week Starts On')) 84 + ->setOptions($this->getWeekDays()) 85 + ->setName($pref_week_start) 86 + ->setCaption( 87 + pht('Calendar weeks will start with this day.')) 88 + ->setValue($preferences->getPreference($pref_week_start, 0))) 89 + ->appendChild( 76 90 id(new AphrontFormSubmitControl()) 77 91 ->setValue(pht('Save Account Settings'))); 78 92 ··· 84 98 85 99 return array( 86 100 $form_box, 101 + ); 102 + } 103 + 104 + private function getWeekDays() { 105 + return array( 106 + pht('Sunday'), 107 + pht('Monday'), 108 + pht('Tuesday'), 109 + pht('Wednesday'), 110 + pht('Thursday'), 111 + pht('Friday'), 112 + pht('Saturday'), 87 113 ); 88 114 } 89 115 }
+1
src/applications/settings/storage/PhabricatorUserPreferences.php
··· 9 9 const PREFERENCE_TITLES = 'titles'; 10 10 const PREFERENCE_MONOSPACED_TEXTAREAS = 'monospaced-textareas'; 11 11 const PREFERENCE_TIME_FORMAT = 'time-format'; 12 + const PREFERENCE_WEEK_START_DAY = 'week-start-day'; 12 13 13 14 const PREFERENCE_RE_PREFIX = 're-prefix'; 14 15 const PREFERENCE_NO_SELF_MAIL = 'self-mail';
+43 -39
src/view/phui/calendar/PHUICalendarMonthView.php
··· 59 59 $days = $this->getDatesInMonth(); 60 60 61 61 $cell_lists = array(); 62 - $empty_cell = array( 63 - 'list' => null, 64 - 'date' => null, 65 - 'uri' => null, 66 - 'count' => 0, 67 - 'class' => null, 68 - ); 69 62 70 63 require_celerity_resource('phui-calendar-month-css'); 71 64 72 65 $first = reset($days); 73 - $start_of_week = 0; 74 - 75 - $empty = $first->format('w'); 76 - 77 - for ($ii = 0; $ii < $empty; $ii++) { 78 - $cell_lists[] = $empty_cell; 79 - } 80 66 81 67 foreach ($days as $day) { 82 68 $day_number = $day->format('j'); ··· 133 119 134 120 foreach ($cell_lists_by_week as $week_of_cell_lists) { 135 121 $cells = array(); 136 - while (count($week_of_cell_lists) < 7) { 137 - $week_of_cell_lists[] = $empty_cell; 138 - } 139 122 foreach ($week_of_cell_lists as $cell_list) { 140 123 $cells[] = $this->getEventListCell($cell_list); 141 124 } ··· 309 292 } 310 293 311 294 private function getDayNamesHeader() { 295 + list($week_start, $week_end) = $this->getWeekStartAndEnd(); 296 + 297 + $weekday_names = array( 298 + $this->getDayHeader(pht('Sun'), pht('Sunday'), true), 299 + $this->getDayHeader(pht('Mon'), pht('Monday')), 300 + $this->getDayHeader(pht('Tue'), pht('Tuesday')), 301 + $this->getDayHeader(pht('Wed'), pht('Wednesday')), 302 + $this->getDayHeader(pht('Thu'), pht('Thursday')), 303 + $this->getDayHeader(pht('Fri'), pht('Friday')), 304 + $this->getDayHeader(pht('Sat'), pht('Saturday'), true), 305 + ); 306 + 307 + $sorted_weekday_names = array(); 308 + 309 + for ($i = $week_start; $i < ($week_start + 7); $i++) { 310 + $sorted_weekday_names[] = $weekday_names[$i % 7]; 311 + } 312 + 312 313 return phutil_tag( 313 314 'tr', 314 315 array('class' => 'phui-calendar-day-of-week-header'), 315 - array( 316 - $this->getDayHeader(pht('Sun'), pht('Sunday'), true), 317 - $this->getDayHeader(pht('Mon'), pht('Monday')), 318 - $this->getDayHeader(pht('Tue'), pht('Tuesday')), 319 - $this->getDayHeader(pht('Wed'), pht('Wednesday')), 320 - $this->getDayHeader(pht('Thu'), pht('Thursday')), 321 - $this->getDayHeader(pht('Fri'), pht('Friday')), 322 - $this->getDayHeader(pht('Sat'), pht('Saturday'), true), 323 - )); 316 + $sorted_weekday_names); 324 317 } 325 318 326 319 private function getDayHeader($short, $long, $is_weekend = false) { ··· 466 459 list($next_year, $next_month) = $this->getNextYearAndMonth(); 467 460 $end_date = new DateTime("{$next_year}-{$next_month}-01", $timezone); 468 461 469 - $start_of_week = 0; 470 - $end_of_week = 6 - $start_of_week; 462 + list($start_of_week, $end_of_week) = $this->getWeekStartAndEnd(); 463 + 471 464 $days_in_month = id(clone $end_date)->modify('-1 day')->format('d'); 472 465 473 466 $first_month_day_date = new DateTime("{$year}-{$month}-01", $timezone); ··· 477 470 $last_weekday_of_month = $last_month_day_date->format('w'); 478 471 479 472 $num_days_display = $days_in_month; 480 - if ($start_of_week < $first_weekday_of_month) { 481 - $num_days_display += $first_weekday_of_month; 473 + if ($start_of_week !== $first_weekday_of_month) { 474 + $interim_start_num = ($first_weekday_of_month + 7 - $start_of_week) % 7; 475 + $num_days_display += $interim_start_num; 476 + $day_date = id(clone $first_month_day_date) 477 + ->modify('-'.$interim_start_num.' days'); 482 478 } 483 - if ($end_of_week > $last_weekday_of_month) { 484 - $num_days_display += (6 - $last_weekday_of_month); 485 - $end_date->modify('+'.(6 - $last_weekday_of_month).' days'); 479 + if ($end_of_week !== $last_weekday_of_month) { 480 + $interim_end_day_num = ($end_of_week - $last_weekday_of_month + 7) % 7; 481 + $num_days_display += $interim_end_day_num; 482 + $end_date->modify('+'.$interim_end_day_num.' days'); 486 483 } 487 484 488 485 $days = array(); 489 - $day_date = id(clone $first_month_day_date) 490 - ->modify('-'.$first_weekday_of_month.' days'); 491 486 492 487 for ($day = 1; $day <= $num_days_display; $day++) { 493 488 $day_epoch = $day_date->format('U'); ··· 513 508 } 514 509 515 510 private function getThisWeekRange() { 516 - $week_start = 0; 517 - $week_end = 6; 511 + list($week_start, $week_end) = $this->getWeekStartAndEnd(); 518 512 519 513 $today = $this->getTodayMidnight(); 520 514 $date_weekday = $today->format('w'); 521 515 522 - $days_from_week_start = $date_weekday - $week_start; 523 - $days_to_week_end = $week_end - $date_weekday + 1; 516 + $days_from_week_start = ($date_weekday + 7 - $week_start) % 7; 517 + $days_to_week_end = 7 - $days_from_week_start; 524 518 525 519 $modify = '-'.$days_from_week_start.' days'; 526 520 $week_start_date = id(clone $today)->modify($modify); ··· 529 523 $week_end_date = id(clone $today)->modify($modify); 530 524 531 525 return array($week_start_date, $week_end_date); 526 + } 527 + 528 + private function getWeekStartAndEnd() { 529 + $preferences = $this->user->loadPreferences(); 530 + $pref_week_start = PhabricatorUserPreferences::PREFERENCE_WEEK_START_DAY; 531 + 532 + $week_start = $preferences->getPreference($pref_week_start, 0); 533 + $week_end = ($week_start + 6) % 7; 534 + 535 + return array($week_start, $week_end); 532 536 } 533 537 534 538 private function getDateTime() {