1
0

test_result_set.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. class TestResultSet {
  3. /** @var Test[] */
  4. private $tests = [];
  5. public function __construct(array $tests = []) {
  6. $this->setTests($tests);
  7. }
  8. /**
  9. * @param Test[] $tests
  10. */
  11. public function setTests(array $tests): void {
  12. $this->tests = $tests;
  13. }
  14. /**
  15. * @return Test[]
  16. */
  17. public function getTests(): array {
  18. return $this->tests;
  19. }
  20. /**
  21. * @param string $dts_start Start date/time in local time
  22. * @param string $dts_end End date/time in local time
  23. * @return Test[]
  24. * @throws Exception
  25. */
  26. public function filterByDateRange(string $dts_start, string $dts_end): array {
  27. $min_unix = strtotime($dts_start);
  28. $max_unix = strtotime($dts_end);
  29. $tests = array_filter($this->tests, static function(Test $test) use ($min_unix, $max_unix) {
  30. $project = $test->getProject();
  31. $dts = $project->dts_report ?: $test->dts_start;
  32. $dt = new DateTime($dts . " UTC");
  33. $unix = $dt->format("U");
  34. if($unix < $min_unix) return false;
  35. if($unix > $max_unix) return false;
  36. return true;
  37. });
  38. $this->tests = array_values($tests);
  39. return $this->tests;
  40. }
  41. }