From fae0ec9220a7971d06b324bbc09709a58a5e294b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 4 Oct 2016 11:41:11 -0700 Subject: [PATCH] Use more CalendarDateTime and fewer epoch timestamps in Calendar Summary: Ref T10747. Moves away from getDateFrom() / getDateTo() and makes a few more date/time methods more consistent. Test Plan: Created, edited, viewed events. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10747 Differential Revision: https://secure.phabricator.com/D16663 --- .../PhabricatorCalendarEventEditEngine.php | 9 +-------- .../editor/PhabricatorCalendarEventEditor.php | 8 ++++---- .../storage/PhabricatorCalendarEvent.php | 16 +++++++++++++--- ...habricatorCalendarEventEndDateTransaction.php | 3 ++- ...bricatorCalendarEventStartDateTransaction.php | 3 ++- ...bricatorCalendarEventUntilDateTransaction.php | 3 ++- .../people/query/PhabricatorPeopleQuery.php | 2 +- 7 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php index 93642a959c..63d33beab4 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditEngine.php @@ -155,13 +155,6 @@ final class PhabricatorCalendarEventEditEngine } if ($this->getIsCreate() || $object->getIsRecurring()) { - $until_datetime = $object->newUntilDateTime(); - if ($until_datetime) { - $until_epoch = $until_datetime->getEpoch(); - } else { - $until_epoch = null; - } - $fields[] = id(new PhabricatorEpochEditField()) ->setAllowNull(true) ->setKey('until') @@ -171,7 +164,7 @@ final class PhabricatorCalendarEventEditEngine ->setDescription(pht('Last instance of the event.')) ->setConduitDescription(pht('Change when the event repeats until.')) ->setConduitTypeDescription(pht('New final event time.')) - ->setValue($until_epoch); + ->setValue($object->getUntilDateTimeEpoch()); } $fields[] = id(new PhabricatorBoolEditField()) diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php index d87746f347..5dd9b463c6 100644 --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php @@ -139,7 +139,7 @@ final class PhabricatorCalendarEventEditor WHERE phid IN (%Ls) AND availabilityCacheTTL >= %d', $user->getTableName(), $phids, - $object->getDateFromForCache()); + $object->getStartDateTimeEpochForCache()); } return $xactions; @@ -159,9 +159,9 @@ final class PhabricatorCalendarEventEditor $recurrence_end_xaction = PhabricatorCalendarEventUntilDateTransaction::TRANSACTIONTYPE; - $start_date = $object->getDateFrom(); - $end_date = $object->getDateTo(); - $recurrence_end = $object->getRecurrenceEndDate(); + $start_date = $object->getStartDateTimeEpoch(); + $end_date = $object->getEndDateTimeEpoch(); + $recurrence_end = $object->getUntilDateTimeEpoch(); $is_recurring = $object->getIsRecurring(); $errors = array(); diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index 6e4d0ce04e..2ddc71115f 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -184,7 +184,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO ->setDescription($parent->getDescription()); $sequence = $this->getSequenceIndex(); - $duration = $this->getDuration(); + $duration = $parent->getDuration(); $epochs = $parent->getSequenceIndexEpochs($actor, $sequence, $duration); $this @@ -277,7 +277,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO } public function getDuration() { - return $this->getDateTo() - $this->getDateFrom(); + return ($this->getEndDateTimeEpoch() - $this->getStartDateTimeEpoch()); } public function getDateEpochForTimezone( @@ -366,7 +366,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO * * @return int Event start date for availability caches. */ - public function getDateFromForCache() { + public function getStartDateTimeEpochForCache() { $epoch = $this->getStartDateTimeEpoch(); $window = phutil_units('15 minutes in seconds'); return ($epoch - $window); @@ -794,6 +794,16 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO return $this->newDateTimeFromEpoch($epoch); } + public function getUntilDateTimeEpoch() { + $datetime = $this->newUntilDateTime(); + + if (!$datetime) { + return null; + } + + return $datetime->getEpoch(); + } + public function newDuration() { return id(new PhutilCalendarDuration()) ->setSeconds($this->getDuration()); diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php index 91d9b396ff..2d5f10d290 100644 --- a/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php +++ b/src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php @@ -6,7 +6,8 @@ final class PhabricatorCalendarEventEndDateTransaction const TRANSACTIONTYPE = 'calendar.enddate'; public function generateOldValue($object) { - return $object->getDateTo(); + // TODO: Upgrade this. + return $object->getEndDateTimeEpoch(); } public function applyInternalEffects($object, $value) { diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php index 90e3b9c9c5..48318edf7e 100644 --- a/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php +++ b/src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php @@ -6,7 +6,8 @@ final class PhabricatorCalendarEventStartDateTransaction const TRANSACTIONTYPE = 'calendar.startdate'; public function generateOldValue($object) { - return $object->getDateFrom(); + // TODO: Upgrade this. + return $object->getStartDateTimeEpoch(); } public function applyInternalEffects($object, $value) { diff --git a/src/applications/calendar/xaction/PhabricatorCalendarEventUntilDateTransaction.php b/src/applications/calendar/xaction/PhabricatorCalendarEventUntilDateTransaction.php index 4cffda8ff6..736ed13704 100644 --- a/src/applications/calendar/xaction/PhabricatorCalendarEventUntilDateTransaction.php +++ b/src/applications/calendar/xaction/PhabricatorCalendarEventUntilDateTransaction.php @@ -6,7 +6,8 @@ final class PhabricatorCalendarEventUntilDateTransaction const TRANSACTIONTYPE = 'calendar.recurrenceenddate'; public function generateOldValue($object) { - return $object->getRecurrenceEndDate(); + // TODO: Upgrade this. + return $object->getUntilDateTimeEpoch(); } public function applyInternalEffects($object, $value) { diff --git a/src/applications/people/query/PhabricatorPeopleQuery.php b/src/applications/people/query/PhabricatorPeopleQuery.php index 5d5650c860..07fbc8b941 100644 --- a/src/applications/people/query/PhabricatorPeopleQuery.php +++ b/src/applications/people/query/PhabricatorPeopleQuery.php @@ -431,7 +431,7 @@ final class PhabricatorPeopleQuery // because of an event, we check again for events after that one ends. while (true) { foreach ($events as $event) { - $from = $event->getDateFromForCache(); + $from = $event->getStartDateTimeEpochForCache(); $to = $event->getEndDateTimeEpoch(); if (($from <= $cursor) && ($to > $cursor)) { $cursor = $to;