diff --git a/app/Repositories/TaskRepository.php b/app/Repositories/TaskRepository.php index 07ce92aa16f6..387979342aeb 100644 --- a/app/Repositories/TaskRepository.php +++ b/app/Repositories/TaskRepository.php @@ -97,9 +97,12 @@ class TaskRepository extends BaseRepository } else { $time_log = []; } + + $key_values = array_column($time_log, 0); + array_multisort($key_values, SORT_ASC, $time_log); // array_multisort($time_log); - ksort($time_log); + // ksort($time_log); if (isset($data['action'])) { if ($data['action'] == 'start') { diff --git a/tests/Feature/TaskApiTest.php b/tests/Feature/TaskApiTest.php index f60cc23189c7..10ac07f65ac6 100644 --- a/tests/Feature/TaskApiTest.php +++ b/tests/Feature/TaskApiTest.php @@ -99,6 +99,42 @@ class TaskApiTest extends TestCase } } + public function testMultiSortArray() + { + + $logs = [ + [1680035007,1680036807,"",true], + [1681156840,1681158000,"",true], + [1680302433,1680387960,"",true], + [1680715620,1680722820,"",true], + [1,1680737460,"",true] + ]; + + $key_values = array_column($logs, 0); + + nlog($logs); + + } + + public function testKsortPerformance() + { + $logs = [ + [1680035007,1680036807,"",true], + [1681156840,1681158000,"",true], + [1680302433,1680387960,"",true], + [1680715620,1680722820,"",true], + [1,1680737460,"",true] + ]; + + $key_values = array_column($logs, 0); + array_multisort($key_values, SORT_ASC, $logs); + + $start = $logs[0]; + + $this->assertEquals(1, $start[0]); + + } + public function testStartStopSanity() {