Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / search / field / PhabricatorSearchDateField.php
blob41decd9503e9436e7bbeca211252df0b74426f83
1 <?php
3 final class PhabricatorSearchDateField
4 extends PhabricatorSearchField {
6 protected function newControl() {
7 return id(new AphrontFormTextControl())
8 ->setPlaceholder(pht('"2022-12-25" or "7 days ago"...'));
11 protected function getValueFromRequest(AphrontRequest $request, $key) {
12 return $request->getStr($key);
15 public function getValueForQuery($value) {
16 return $this->parseDateTime($value);
19 protected function validateControlValue($value) {
20 if (!strlen($value)) {
21 return;
24 $epoch = $this->parseDateTime($value);
25 if ($epoch) {
26 return;
29 $this->addError(
30 pht('Invalid'),
31 pht('Date value for "%s" can not be parsed.', $this->getLabel()));
34 protected function parseDateTime($value) {
35 if (!strlen($value)) {
36 return null;
39 // If this appears to be an epoch timestamp, just return it unmodified.
40 // This assumes values like "2016" or "20160101" are "Ymd".
41 if (is_int($value) || ctype_digit($value)) {
42 if ((int)$value > 30000000) {
43 return (int)$value;
47 return PhabricatorTime::parseLocalTime($value, $this->getViewer());
50 protected function newConduitParameterType() {
51 return new ConduitEpochParameterType();