mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Fixes for tests
This commit is contained in:
parent
4b397b5b39
commit
a18806f986
@ -113,7 +113,7 @@ class TaskRepository extends BaseRepository
|
||||
|
||||
foreach($time_log as $key => $value)
|
||||
{
|
||||
$time_log[$key][1] = $this->roundTimeLog($time_log[$key][1]);
|
||||
$time_log[$key][1] = $this->roundTimeLog($time_log[$key][0], $time_log[$key][1]);
|
||||
}
|
||||
|
||||
if (isset($data['action'])) {
|
||||
@ -252,17 +252,31 @@ class TaskRepository extends BaseRepository
|
||||
return $task;
|
||||
}
|
||||
|
||||
public function roundTimeLog(int $end_time): int
|
||||
public function roundTimeLog(int $start_time, int $end_time): int
|
||||
{
|
||||
if($this->task_round_to_nearest == 1)
|
||||
return $end_time;
|
||||
|
||||
if($this->task_round_up)
|
||||
return (int)ceil($end_time/$this->task_round_to_nearest)*$this->task_round_to_nearest;
|
||||
$interval = $end_time - $start_time;
|
||||
|
||||
if($this->task_round_up)
|
||||
return $start_time + (int)ceil($interval/$this->task_round_to_nearest)*$this->task_round_to_nearest;
|
||||
|
||||
return $start_time - (int)floor($interval/$this->task_round_to_nearest) * $this->task_round_to_nearest;
|
||||
|
||||
return (int)floor($end_time/$this->task_round_to_nearest) * $this->task_round_to_nearest;
|
||||
}
|
||||
|
||||
// public function roundTimeLog(int $end_time): int
|
||||
// {
|
||||
// if($this->task_round_to_nearest == 1)
|
||||
// return $end_time;
|
||||
|
||||
// if($this->task_round_up)
|
||||
// return (int)ceil($end_time/$this->task_round_to_nearest)*$this->task_round_to_nearest;
|
||||
|
||||
// return (int)floor($end_time/$this->task_round_to_nearest) * $this->task_round_to_nearest;
|
||||
// }
|
||||
|
||||
public function stop(Task $task)
|
||||
{
|
||||
$this->init($task);
|
||||
@ -272,7 +286,7 @@ class TaskRepository extends BaseRepository
|
||||
$last = end($log);
|
||||
|
||||
if (is_array($last) && $last[1] === 0) {
|
||||
$last[1] = $this->roundTimeLog(time());
|
||||
$last[1] = $this->roundTimeLog($last[0], time());
|
||||
|
||||
array_pop($log);
|
||||
$log = array_merge($log, [$last]);//check at this point, it may be prepending here.
|
||||
|
@ -42,6 +42,79 @@ class TaskRoundingTest extends TestCase
|
||||
|
||||
}
|
||||
|
||||
public function testRoundUp2()
|
||||
{
|
||||
|
||||
|
||||
|
||||
$start_time = 1715237056;
|
||||
$end_time = $start_time + 60*7;
|
||||
$this->task_round_to_nearest = 600;
|
||||
|
||||
$rounded = $start_time + 60*10;
|
||||
|
||||
$this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
|
||||
|
||||
|
||||
}
|
||||
|
||||
public function testRoundUp3()
|
||||
{
|
||||
|
||||
|
||||
$start_time = 1715213100;
|
||||
$end_time = $start_time + 60*15;
|
||||
$this->task_round_to_nearest = 900;
|
||||
|
||||
$rounded = $start_time + 60*15;
|
||||
|
||||
$this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
|
||||
|
||||
|
||||
$s = \Carbon\Carbon::createFromTimestamp($start_time);
|
||||
|
||||
$e = \Carbon\Carbon::createFromTimestamp($end_time);
|
||||
|
||||
$x = \Carbon\Carbon::createFromTimestamp($rounded);
|
||||
|
||||
|
||||
// echo $s->format('Y-m-d H:i:s').PHP_EOL;
|
||||
// echo $e->format('Y-m-d H:i:s').PHP_EOL;
|
||||
// echo $x->format('Y-m-d H:i:s').PHP_EOL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
// public function testRoundUp4()
|
||||
// {
|
||||
|
||||
|
||||
|
||||
// $start_time = 1715238900;
|
||||
// $end_time = 1715238000;
|
||||
// // $end_time = $start_time + 60*15;
|
||||
// $this->task_round_to_nearest = 900;
|
||||
|
||||
// $rounded = $start_time + 60*15;
|
||||
|
||||
// $this->assertEquals($rounded, $this->roundTimeLog($start_time, $end_time));
|
||||
|
||||
|
||||
// $s = \Carbon\Carbon::createFromTimestamp($start_time);
|
||||
|
||||
// $e = \Carbon\Carbon::createFromTimestamp($end_time);
|
||||
|
||||
// $x = \Carbon\Carbon::createFromTimestamp($rounded);
|
||||
|
||||
|
||||
// echo $s->format('Y-m-d H:i:s').PHP_EOL;
|
||||
// echo $e->format('Y-m-d H:i:s').PHP_EOL;
|
||||
// echo $x->format('Y-m-d H:i:s').PHP_EOL;
|
||||
|
||||
|
||||
// }
|
||||
|
||||
|
||||
public function testRoundDown()
|
||||
{
|
||||
$start_time = 1714942800;
|
||||
|
Loading…
x
Reference in New Issue
Block a user