From e4c9914697037ffb83b904e1ee34a1ccb6293531 Mon Sep 17 00:00:00 2001 From: lkassianik Date: Mon, 25 May 2015 11:19:57 -0700 Subject: [PATCH] Multi-day events should be correctly calculated for new js layout Summary: Fixes T8304, Multi-day events should be correctly calculated for new js layout Test Plan: A day with events starting before midnight of the displayed day should be correctly placed and fitted for day view. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T8304 Differential Revision: https://secure.phabricator.com/D13008 --- src/infrastructure/time/PhabricatorTime.php | 6 ++++++ src/view/phui/calendar/PHUICalendarDayView.php | 12 ++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/infrastructure/time/PhabricatorTime.php b/src/infrastructure/time/PhabricatorTime.php index e31222cf76..2adcc95d49 100644 --- a/src/infrastructure/time/PhabricatorTime.php +++ b/src/infrastructure/time/PhabricatorTime.php @@ -72,4 +72,10 @@ final class PhabricatorTime { return $today; } + public static function getDateTimeFromEpoch($epoch, PhabricatorUser $viewer) { + $datetime = new DateTime('@'.$epoch); + $datetime->setTimeZone($viewer->getTimeZone()); + return $datetime; + } + } diff --git a/src/view/phui/calendar/PHUICalendarDayView.php b/src/view/phui/calendar/PHUICalendarDayView.php index 2187d08341..9bdab3fc4b 100644 --- a/src/view/phui/calendar/PHUICalendarDayView.php +++ b/src/view/phui/calendar/PHUICalendarDayView.php @@ -103,8 +103,16 @@ final class PHUICalendarDayView extends AphrontView { $event->getEpochEnd() > $day_start_epoch) { if ($first_event_hour === null) { - $first_event_hour = new DateTime('@'.$event->getEpochStart()); - $first_event_hour->setTimeZone($viewer->getTimeZone()); + $first_event_hour = PhabricatorTime::getDateTimeFromEpoch( + $event->getEpochStart(), + $viewer); + + $midnight = $this->getDateTime()->setTime(0, 0, 0); + + if ($first_event_hour->format('U') < $midnight->format('U')) { + $first_event_hour = clone $midnight; + } + $eight_am = $this->getDateTime()->setTime(8, 0, 0); if ($eight_am->format('U') < $first_event_hour->format('U')) { $first_event_hour = clone $eight_am;