public static function parseLocalTime($time, PhabricatorUser $user) { $old_zone = date_default_timezone_get(); date_default_timezone_set($user->getTimezoneIdentifier()); $timestamp = (int) strtotime($time, self::getNow()); if ($timestamp <= 0) { $timestamp = null; } date_default_timezone_set($old_zone); return $timestamp; }
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 (strtolower($start_day_str) == 'today' || $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); }
public function applyViewerTimezone(PhabricatorUser $viewer) { $this->viewerTimezone = $viewer->getTimezoneIdentifier(); return $this; }
private function updateEventFromNode(PhabricatorUser $actor, PhabricatorCalendarEvent $event, PhutilCalendarEventNode $node) { $instance_epoch = $this->getNodeInstanceEpoch($node); $event->setUTCInstanceEpoch($instance_epoch); $timezone = $actor->getTimezoneIdentifier(); // TODO: These should be transactional, but the transaction only accepts // epoch timestamps right now. $start_datetime = $node->getStartDateTime()->setViewerTimezone($timezone); $end_datetime = $node->getEndDateTime()->setViewerTimezone($timezone); $event->setStartDateTime($start_datetime)->setEndDateTime($end_datetime); $event->setIsAllDay((int) $start_datetime->getIsAllDay()); // TODO: This should be transactional, but the transaction only accepts // simple frequency rules right now. $rrule = $node->getRecurrenceRule(); if ($rrule) { $event->setRecurrenceRule($rrule); $until_datetime = $rrule->getUntil(); if ($until_datetime) { $until_datetime->setViewerTimezone($timezone); $event->setUntilDateTime($until_datetime); } $count = $rrule->getCount(); $event->setParameter('recurrenceCount', $count); } return $event; }