@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.

Conpherence - implement epoch creation slightly differently

Summary: D6114 fixed some bugs but on production it shows up as a new bug where Saturday is the first day? stop messing with the DateTime object so much and do some old school epoch manipulation. This works correctly on my laptop and my still fail in production, but it will rule out DateTime suckage.

Test Plan: still works on laptop

Reviewers: epriestley, chad

Reviewed By: epriestley

CC: aran, Korvin

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

+128 -37
+3
src/__phutil_library_map__.php
··· 272 272 'ConpherenceThreadListView' => 'applications/conpherence/view/ConpherenceThreadListView.php', 273 273 'ConpherenceThreadMailReceiver' => 'applications/conpherence/mail/ConpherenceThreadMailReceiver.php', 274 274 'ConpherenceThreadQuery' => 'applications/conpherence/query/ConpherenceThreadQuery.php', 275 + 'ConpherenceTimeUtil' => 'applications/conpherence/util/ConpherenceTimeUtil.php', 276 + 'ConpherenceTimeUtilTestCase' => 'applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php', 275 277 'ConpherenceTransaction' => 'applications/conpherence/storage/ConpherenceTransaction.php', 276 278 'ConpherenceTransactionComment' => 'applications/conpherence/storage/ConpherenceTransactionComment.php', 277 279 'ConpherenceTransactionQuery' => 'applications/conpherence/query/ConpherenceTransactionQuery.php', ··· 2121 2123 'ConpherenceThreadListView' => 'AphrontView', 2122 2124 'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver', 2123 2125 'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 2126 + 'ConpherenceTimeUtilTestCase' => 'PhabricatorTestCase', 2124 2127 'ConpherenceTransaction' => 'PhabricatorApplicationTransaction', 2125 2128 'ConpherenceTransactionComment' => 'PhabricatorApplicationTransactionComment', 2126 2129 'ConpherenceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+59
src/applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php
··· 1 + <?php 2 + 3 + final class ConpherenceTimeUtilTestCase extends PhabricatorTestCase { 4 + 5 + public function testWidgetTimestampsAtMidnight() { 6 + $u = new PhabricatorUser(); 7 + $u->setTimezoneIdentifier('America/Los_Angeles'); 8 + $days = $this->getAllDays(); 9 + foreach ($days as $day) { 10 + $data = ConpherenceTimeUtil::getCalendarWidgetTimestamps( 11 + $u, 12 + $day); 13 + 14 + $this->assertEqual( 15 + '000000', 16 + $data['epoch_stamps'][0]->format('His')); 17 + } 18 + } 19 + 20 + public function testWidgetTimestampsStartDay() { 21 + $u = new PhabricatorUser(); 22 + $u->setTimezoneIdentifier('America/Los_Angeles'); 23 + $days = $this->getAllDays(); 24 + foreach ($days as $day) { 25 + $data = ConpherenceTimeUtil::getCalendarWidgetTimestamps( 26 + $u, 27 + $day); 28 + 29 + $this->assertEqual( 30 + $day, 31 + $data['epoch_stamps'][0]->format('l')); 32 + } 33 + 34 + $t = 1370202281; // 2013-06-02 12:44:41 -0700 -- a Sunday 35 + $time = PhabricatorTime::pushTime($t, 'America/Los_Angeles'); 36 + foreach ($days as $day) { 37 + $data = ConpherenceTimeUtil::getCalendarWidgetTimestamps( 38 + $u, 39 + $day); 40 + 41 + $this->assertEqual( 42 + $day, 43 + $data['epoch_stamps'][0]->format('l')); 44 + } 45 + unset($time); 46 + } 47 + 48 + private function getAllDays() { 49 + return array( 50 + 'Sunday', 51 + 'Monday', 52 + 'Tuesday', 53 + 'Wednesday', 54 + 'Thursday', 55 + 'Friday', 56 + 'Saturday'); 57 + } 58 + 59 + }
+2 -25
src/applications/conpherence/controller/ConpherenceWidgetController.php
··· 200 200 $content = array(); 201 201 $layout = id(new AphrontMultiColumnView()) 202 202 ->setFluidLayout(true); 203 - $timestamps = $this->getCalendarWidgetTimestamps(); 203 + $timestamps = ConpherenceTimeUtil::getCalendarWidgetTimestamps($user); 204 204 $today = $timestamps['today']; 205 205 $epoch_stamps = $timestamps['epoch_stamps']; 206 206 $one_day = 24 * 60 * 60; ··· 378 378 ); 379 379 } 380 380 381 - private function getCalendarWidgetTimestamps() { 382 - $user = $this->getRequest()->getUser(); 383 - $timezone = new DateTimeZone($user->getTimezoneIdentifier()); 384 - 385 - $start_epoch = phabricator_format_local_time( 386 - strtotime('last sunday', strtotime('tomorrow')), 387 - $user, 388 - 'U'); 389 - $first_day = new DateTime('@'.$start_epoch, $timezone); 390 - $timestamps = array(); 391 - for ($day = 0; $day < 9; $day++) { 392 - $timestamp = clone $first_day; 393 - $timestamp->modify(sprintf('+%d days', $day)); 394 - // set the timezone again 'cuz DateTime is weird 395 - $timestamp->setTimeZone($timezone); 396 - $timestamps[] = $timestamp; 397 - } 398 - return array( 399 - 'today' => new DateTime('today', $timezone), 400 - 'epoch_stamps' => $timestamps 401 - ); 402 - } 403 - 404 381 private function getWidgetURI() { 405 382 $conpherence = $this->getConpherence(); 406 383 return $this->getApplicationURI('update/'.$conpherence->getID().'/'); 407 384 } 408 385 409 - } 386 + }
+4 -12
src/applications/conpherence/query/ConpherenceThreadQuery.php
··· 216 216 $participant_phids = array_mergev($participant_phids); 217 217 $file_phids = array_mergev($file_phids); 218 218 219 - // statuses of everyone currently in the conpherence 220 - // we show sunday -> saturday in a list *AND* a window 221 - // of today -> +2 days. Ergo, if its saturday we need 222 - // +2 days, for +9 days total. 223 - $start_epoch = phabricator_format_local_time( 224 - strtotime('last sunday', strtotime('tomorrow')), 225 - $this->getViewer(), 226 - 'U'); 227 - $end_epoch = phabricator_format_local_time( 228 - strtotime('last sunday +9 days', strtotime('tomorrow')), 229 - $this->getViewer(), 230 - 'U'); 219 + $epochs = ConpherenceTimeUtil::getCalendarEventEpochs( 220 + $this->getViewer()); 221 + $start_epoch = $epochs['start_epoch']; 222 + $end_epoch = $epochs['end_epoch']; 231 223 $statuses = id(new PhabricatorUserStatus()) 232 224 ->loadAllWhere( 233 225 'userPHID in (%Ls) AND dateTo >= %d AND dateFrom <= %d',
+60
src/applications/conpherence/util/ConpherenceTimeUtil.php
··· 1 + <?php 2 + 3 + final class ConpherenceTimeUtil { 4 + 5 + public static function getCalendarEventEpochs( 6 + PhabricatorUser $user, 7 + $start_day_str = 'Sunday') { 8 + 9 + $objects = self::getStartDateTimeObjects($user, $start_day_str); 10 + $start_day = $objects['start_day']; 11 + $end_day = clone $start_day; 12 + $end_day->modify('+9 days'); 13 + 14 + return array( 15 + 'start_epoch' => $start_day->format('U'), 16 + 'end_epoch' => $end_day->format('U')); 17 + } 18 + 19 + public static function getCalendarWidgetTimestamps( 20 + PhabricatorUser $user, 21 + $start_day_str = 'Sunday') { 22 + 23 + $objects = self::getStartDateTimeObjects($user, $start_day_str); 24 + $start_day = $objects['start_day']; 25 + $timestamps = array(); 26 + for ($day = 0; $day < 9; $day++) { 27 + $timestamp = clone $start_day; 28 + $timestamp->modify(sprintf('+%d days', $day)); 29 + $timestamps[] = $timestamp; 30 + } 31 + return array( 32 + 'today' => $objects['today'], 33 + 'epoch_stamps' => $timestamps 34 + ); 35 + } 36 + 37 + private static function getStartDateTimeObjects( 38 + PhabricatorUser $user, 39 + $start_day_str) { 40 + $timezone = new DateTimeZone($user->getTimezoneIdentifier()); 41 + 42 + $today_epoch = PhabricatorTime::parseLocalTime('today', $user); 43 + $today = new DateTime('@'.$today_epoch); 44 + $today->setTimeZone($timezone); 45 + 46 + if ($today->format('l') == $start_day_str) { 47 + $start_day = clone $today; 48 + } else { 49 + $start_epoch = PhabricatorTime::parseLocalTime( 50 + 'last '.$start_day_str, 51 + $user); 52 + $start_day = new DateTime('@'.$start_epoch); 53 + $start_day->setTimeZone($timezone); 54 + } 55 + return array( 56 + 'today' => $today, 57 + 'start_day' => $start_day); 58 + } 59 + 60 + }