Skip to content

Commit

Permalink
EWPP-2957: Minor timestamp generation refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
upchuk committed May 8, 2023
1 parent 32ccfbc commit 81e4741
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/Plugin/facets/query_type/DateStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,11 @@ public function execute() {
$filter = $query->createConditionGroup('OR', ['facet:' . $field_identifier]);
foreach ($active_items as $value) {
if ($value === self::PAST) {
$filter->addCondition($field_identifier, $now->getTimestamp(), "<=");
$filter->addCondition($field_identifier, $this->prepareTimestamp($now), "<=");
}
elseif ($value === self::UPCOMING) {
$condition_group = $query->createConditionGroup('OR');
$condition_group->addCondition($field_identifier, $now->getTimestamp(), ">");
$condition_group->addCondition($field_identifier, $this->prepareTimestamp($now), ">");
$condition_group->addCondition($field_identifier, NULL);
$filter->addConditionGroup($condition_group);
}
Expand Down Expand Up @@ -139,7 +139,7 @@ public function build() {
if (!empty($this->results)) {
foreach ($this->results as $result) {
$result_filter = trim($result['filter'], '"');
$now->getTimestamp() > $result_filter ? $count[self::UPCOMING]++ : $count[self::PAST]++;
$this->prepareTimestamp($now) > $result_filter ? $count[self::UPCOMING]++ : $count[self::PAST]++;
}
}

Expand Down Expand Up @@ -184,4 +184,11 @@ protected function applySort(QueryInterface $query, array $active_items, string
$sorts[$field_name] = $item === self::PAST ? 'DESC' : 'ASC';
}

/**
* Prepares the timestamp to be used in the query.
*/
protected function prepareTimestamp(DrupalDateTime $date): int {
return $date->getTimestamp();
}

}

0 comments on commit 81e4741

Please sign in to comment.