2015-06-05 11:21:08 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSearchDateField
|
|
|
|
extends PhabricatorSearchField {
|
|
|
|
|
|
|
|
protected function newControl() {
|
2018-01-26 08:37:13 -08:00
|
|
|
return id(new AphrontFormTextControl())
|
|
|
|
->setPlaceholder(pht('"2022-12-25" or "7 days ago"...'));
|
2015-06-05 11:21:08 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getValueFromRequest(AphrontRequest $request, $key) {
|
|
|
|
return $request->getStr($key);
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:22 -07:00
|
|
|
public function getValueForQuery($value) {
|
|
|
|
return $this->parseDateTime($value);
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:08 -07:00
|
|
|
protected function validateControlValue($value) {
|
|
|
|
if (!strlen($value)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$epoch = $this->parseDateTime($value);
|
|
|
|
if ($epoch) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->addError(
|
|
|
|
pht('Invalid'),
|
|
|
|
pht('Date value for "%s" can not be parsed.', $this->getLabel()));
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function parseDateTime($value) {
|
|
|
|
if (!strlen($value)) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-07-26 07:06:25 -07:00
|
|
|
// 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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:08 -07:00
|
|
|
return PhabricatorTime::parseLocalTime($value, $this->getViewer());
|
|
|
|
}
|
|
|
|
|
2015-12-13 06:52:37 -08:00
|
|
|
protected function newConduitParameterType() {
|
|
|
|
return new ConduitEpochParameterType();
|
|
|
|
}
|
|
|
|
|
2015-06-05 11:21:08 -07:00
|
|
|
}
|