public function testParseLocalTime() { $u = new PhabricatorUser(); $u->setTimezoneIdentifier('UTC'); $v = new PhabricatorUser(); $v->setTimezoneIdentifier('America/Los_Angeles'); $t = 1370202281; // 2013-06-02 12:44:41 -0700 $time = PhabricatorTime::pushTime($t, 'America/Los_Angeles'); $this->assertEqual($t, PhabricatorTime::parseLocalTime('now', $u)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('now', $v)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $u)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 -0700', $v)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $u)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41 PDT', $v)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 19:44:41', $u)); $this->assertEqual($t, PhabricatorTime::parseLocalTime('2013-06-02 12:44:41', $v)); $this->assertEqual($t + 3600, PhabricatorTime::parseLocalTime('+1 hour', $u)); $this->assertEqual($t + 3600, PhabricatorTime::parseLocalTime('+1 hour', $v)); unset($time); $t = 1370239200; // 2013-06-02 23:00:00 -0700 $time = PhabricatorTime::pushTime($t, 'America/Los_Angeles'); // For the UTC user, midnight was 6 hours ago because it's early in the // morning for htem. For the PDT user, midnight was 23 hours ago. $this->assertEqual($t + -6 * 3600 + 60, PhabricatorTime::parseLocalTime('12:01:00 AM', $u)); $this->assertEqual($t + -23 * 3600 + 60, PhabricatorTime::parseLocalTime('12:01:00 AM', $v)); unset($time); }
protected function parseDateTime($value) { if (!strlen($value)) { return null; } return PhabricatorTime::parseLocalTime($value, $this->getViewer()); }
protected function parseDateTime($value) { if (!strlen($value)) { return null; } // If this appears to be an epoch timestamp, just return it unmodified. // This assumes values like "2016" or "20160101" are "Ymd". if (is_int($value) || ctype_digit($value)) { if ((int) $value > 30000000) { return (int) $value; } } return PhabricatorTime::parseLocalTime($value, $this->getViewer()); }
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 getWindow($request) { $window_str = $request->getStr('window', '12 AM 7 days ago'); $error = null; // Do locale-aware parsing so that the user's timezone is assumed for // time windows like "3 PM", rather than assuming the server timezone. $window_epoch = PhabricatorTime::parseLocalTime($window_str, $this->user); if ($window_epoch === null) { $error = 'Invalid'; $window_epoch = time() - 60 * 60 * 24 * 7; } // If the time ends up in the future, convert it to the corresponding time // and equal distance in the past. This is so users can type "6 days" (which // means "6 days from now") and get the behavior of "6 days ago", rather // than no results (because the window epoch is in the future). This might // be a little confusing because it casues "tomorrow" to mean "yesterday" // and "2022" (or whatever) to mean "ten years ago", but these inputs are // nonsense anyway. if ($window_epoch > time()) { $window_epoch = time() - ($window_epoch - time()); } return array($window_str, $window_epoch, $error); }
/** * @task dates */ protected function parseDateTime($date_time) { if (!strlen($date_time)) { return null; } return PhabricatorTime::parseLocalTime($date_time, $this->requireViewer()); }
public function applyApplicationSearchConstraintToQuery(PhabricatorApplicationSearchEngine $engine, PhabricatorCursorPagedPolicyAwareQuery $query, $value) { $viewer = $this->getViewer(); if (!is_array($value)) { $value = array(); } $min_str = idx($value, 'min', ''); if (strlen($min_str)) { $min = PhabricatorTime::parseLocalTime($min_str, $viewer); } else { $min = null; } $max_str = idx($value, 'max', ''); if (strlen($max_str)) { $max = PhabricatorTime::parseLocalTime($max_str, $viewer); } else { $max = null; } if ($min !== null || $max !== null) { $query->withApplicationSearchRangeConstraint($this->newNumericIndex(null), $min, $max); } }
/** * From request parameters, figure out where we should jump to in the log. * We jump to either a date or log ID, but load a few lines of context before * it so the user can see the nearby conversation. */ private function getPagingParameters(AphrontRequest $request, PhabricatorChatLogQuery $query) { $viewer = $request->getViewer(); $at_id = $request->getInt('at'); $at_date = $request->getStr('date'); $context_log = null; $map = array(); $query = clone $query; $query->setLimit(8); if ($at_id) { // Jump to the log in question, and load a few lines of context before // it. $context_logs = $query->setAfterID($at_id)->execute(); $context_log = last($context_logs); $map = array($at_id => true); } else { if ($at_date) { $timestamp = PhabricatorTime::parseLocalTime($at_date, $viewer); if ($timestamp) { $context_logs = $query->withMaximumEpoch($timestamp)->execute(); $context_log = last($context_logs); $target_log = head($context_logs); if ($target_log) { $map = array($target_log->getID() => true); } } } } if ($context_log) { $after = null; $before = $context_log->getID() - 1; } else { $after = $request->getInt('after'); $before = $request->getInt('before'); } return array($after, $before, $map); }
public function newDateControl($proxy, $time) { $control = id(new AphrontFormDateControl())->setLabel($proxy->getFieldName())->setName($proxy->getFieldKey())->setUser($proxy->getViewer())->setCaption($proxy->getCaption())->setAllowNull(!$proxy->getRequired())->setInitialTime($time); $value = $proxy->getFieldValue(); if (!ctype_digit($value)) { $value = PhabricatorTime::parseLocalTime($value, $proxy->getViewer()); } $control->setValue(nonempty($value, null)); return $control; }