test_result_set.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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) {
  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. */
  25. public function filterByDateRange(string $dts_start, string $dts_end): array {
  26. $min_unix = strtotime($dts_start);
  27. $max_unix = strtotime($dts_end);
  28. $tests = array_filter($this->tests, function(Test $test) use ($min_unix, $max_unix) {
  29. $project = $test->getProject();
  30. $dts = $project->dts_report ?: $test->dts_start;
  31. $dt = new DateTime($dts . " UTC");
  32. $unix = $dt->format("U");
  33. if($unix < $min_unix) return false;
  34. if($unix > $max_unix) return false;
  35. return true;
  36. });
  37. $this->tests = array_values($tests);
  38. return $this->tests;
  39. }
  40. }