1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-10 23:01:04 +01:00

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
This commit is contained in:
Bob Trahan 2013-06-03 15:40:00 -07:00
parent 029fa5b1f3
commit 03b1ecbcdd
5 changed files with 128 additions and 37 deletions

View file

@ -272,6 +272,8 @@ phutil_register_library_map(array(
'ConpherenceThreadListView' => 'applications/conpherence/view/ConpherenceThreadListView.php',
'ConpherenceThreadMailReceiver' => 'applications/conpherence/mail/ConpherenceThreadMailReceiver.php',
'ConpherenceThreadQuery' => 'applications/conpherence/query/ConpherenceThreadQuery.php',
'ConpherenceTimeUtil' => 'applications/conpherence/util/ConpherenceTimeUtil.php',
'ConpherenceTimeUtilTestCase' => 'applications/conpherence/__tests__/ConpherenceTimeUtilTestCase.php',
'ConpherenceTransaction' => 'applications/conpherence/storage/ConpherenceTransaction.php',
'ConpherenceTransactionComment' => 'applications/conpherence/storage/ConpherenceTransactionComment.php',
'ConpherenceTransactionQuery' => 'applications/conpherence/query/ConpherenceTransactionQuery.php',
@ -2121,6 +2123,7 @@ phutil_register_library_map(array(
'ConpherenceThreadListView' => 'AphrontView',
'ConpherenceThreadMailReceiver' => 'PhabricatorObjectMailReceiver',
'ConpherenceThreadQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'ConpherenceTimeUtilTestCase' => 'PhabricatorTestCase',
'ConpherenceTransaction' => 'PhabricatorApplicationTransaction',
'ConpherenceTransactionComment' => 'PhabricatorApplicationTransactionComment',
'ConpherenceTransactionQuery' => 'PhabricatorApplicationTransactionQuery',

View file

@ -0,0 +1,59 @@
<?php
final class ConpherenceTimeUtilTestCase extends PhabricatorTestCase {
public function testWidgetTimestampsAtMidnight() {
$u = new PhabricatorUser();
$u->setTimezoneIdentifier('America/Los_Angeles');
$days = $this->getAllDays();
foreach ($days as $day) {
$data = ConpherenceTimeUtil::getCalendarWidgetTimestamps(
$u,
$day);
$this->assertEqual(
'000000',
$data['epoch_stamps'][0]->format('His'));
}
}
public function testWidgetTimestampsStartDay() {
$u = new PhabricatorUser();
$u->setTimezoneIdentifier('America/Los_Angeles');
$days = $this->getAllDays();
foreach ($days as $day) {
$data = ConpherenceTimeUtil::getCalendarWidgetTimestamps(
$u,
$day);
$this->assertEqual(
$day,
$data['epoch_stamps'][0]->format('l'));
}
$t = 1370202281; // 2013-06-02 12:44:41 -0700 -- a Sunday
$time = PhabricatorTime::pushTime($t, 'America/Los_Angeles');
foreach ($days as $day) {
$data = ConpherenceTimeUtil::getCalendarWidgetTimestamps(
$u,
$day);
$this->assertEqual(
$day,
$data['epoch_stamps'][0]->format('l'));
}
unset($time);
}
private function getAllDays() {
return array(
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday');
}
}

View file

@ -200,7 +200,7 @@ final class ConpherenceWidgetController extends
$content = array();
$layout = id(new AphrontMultiColumnView())
->setFluidLayout(true);
$timestamps = $this->getCalendarWidgetTimestamps();
$timestamps = ConpherenceTimeUtil::getCalendarWidgetTimestamps($user);
$today = $timestamps['today'];
$epoch_stamps = $timestamps['epoch_stamps'];
$one_day = 24 * 60 * 60;
@ -378,32 +378,9 @@ final class ConpherenceWidgetController extends
);
}
private function getCalendarWidgetTimestamps() {
$user = $this->getRequest()->getUser();
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$start_epoch = phabricator_format_local_time(
strtotime('last sunday', strtotime('tomorrow')),
$user,
'U');
$first_day = new DateTime('@'.$start_epoch, $timezone);
$timestamps = array();
for ($day = 0; $day < 9; $day++) {
$timestamp = clone $first_day;
$timestamp->modify(sprintf('+%d days', $day));
// set the timezone again 'cuz DateTime is weird
$timestamp->setTimeZone($timezone);
$timestamps[] = $timestamp;
}
return array(
'today' => new DateTime('today', $timezone),
'epoch_stamps' => $timestamps
);
}
private function getWidgetURI() {
$conpherence = $this->getConpherence();
return $this->getApplicationURI('update/'.$conpherence->getID().'/');
}
}
}

View file

@ -216,18 +216,10 @@ final class ConpherenceThreadQuery
$participant_phids = array_mergev($participant_phids);
$file_phids = array_mergev($file_phids);
// statuses of everyone currently in the conpherence
// we show sunday -> saturday in a list *AND* a window
// of today -> +2 days. Ergo, if its saturday we need
// +2 days, for +9 days total.
$start_epoch = phabricator_format_local_time(
strtotime('last sunday', strtotime('tomorrow')),
$this->getViewer(),
'U');
$end_epoch = phabricator_format_local_time(
strtotime('last sunday +9 days', strtotime('tomorrow')),
$this->getViewer(),
'U');
$epochs = ConpherenceTimeUtil::getCalendarEventEpochs(
$this->getViewer());
$start_epoch = $epochs['start_epoch'];
$end_epoch = $epochs['end_epoch'];
$statuses = id(new PhabricatorUserStatus())
->loadAllWhere(
'userPHID in (%Ls) AND dateTo >= %d AND dateFrom <= %d',

View file

@ -0,0 +1,60 @@
<?php
final class ConpherenceTimeUtil {
public static function getCalendarEventEpochs(
PhabricatorUser $user,
$start_day_str = 'Sunday') {
$objects = self::getStartDateTimeObjects($user, $start_day_str);
$start_day = $objects['start_day'];
$end_day = clone $start_day;
$end_day->modify('+9 days');
return array(
'start_epoch' => $start_day->format('U'),
'end_epoch' => $end_day->format('U'));
}
public static function getCalendarWidgetTimestamps(
PhabricatorUser $user,
$start_day_str = 'Sunday') {
$objects = self::getStartDateTimeObjects($user, $start_day_str);
$start_day = $objects['start_day'];
$timestamps = array();
for ($day = 0; $day < 9; $day++) {
$timestamp = clone $start_day;
$timestamp->modify(sprintf('+%d days', $day));
$timestamps[] = $timestamp;
}
return array(
'today' => $objects['today'],
'epoch_stamps' => $timestamps
);
}
private static function getStartDateTimeObjects(
PhabricatorUser $user,
$start_day_str) {
$timezone = new DateTimeZone($user->getTimezoneIdentifier());
$today_epoch = PhabricatorTime::parseLocalTime('today', $user);
$today = new DateTime('@'.$today_epoch);
$today->setTimeZone($timezone);
if ($today->format('l') == $start_day_str) {
$start_day = clone $today;
} else {
$start_epoch = PhabricatorTime::parseLocalTime(
'last '.$start_day_str,
$user);
$start_day = new DateTime('@'.$start_epoch);
$start_day->setTimeZone($timezone);
}
return array(
'today' => $today,
'start_day' => $start_day);
}
}