Fixes for utc offset for task start dates

This commit is contained in:
David Bomba 2023-08-21 08:20:51 +10:00
parent 8e5772e3c1
commit a7290dd251
2 changed files with 11 additions and 4 deletions

View File

@ -880,6 +880,13 @@ class Company extends BaseModel
return $data; return $data;
} }
public function utc_offset(): int
{
$timezone = $this->timezone();
return $timezone->utc_offset ?? 0;
}
public function timezone_offset(): int public function timezone_offset(): int
{ {
$offset = 0; $offset = 0;

View File

@ -118,7 +118,7 @@ class TaskRepository extends BaseRepository
$task->is_running = $data['is_running'] ? 1 : 0; $task->is_running = $data['is_running'] ? 1 : 0;
} }
$task->calculated_start_date = $this->harvestStartDate($time_log); $task->calculated_start_date = $this->harvestStartDate($time_log, $task);
$task->time_log = json_encode($time_log); $task->time_log = json_encode($time_log);
@ -133,11 +133,11 @@ class TaskRepository extends BaseRepository
return $task; return $task;
} }
private function harvestStartDate($time_log) private function harvestStartDate($time_log, $task)
{ {
if(isset($time_log[0][0])){ if(isset($time_log[0][0])){
return \Carbon\Carbon::createFromTimestamp($time_log[0][0]); return \Carbon\Carbon::createFromTimestamp($time_log[0][0])->addSeconds($task->company->utc_offset());
} }
return null; return null;
@ -218,7 +218,7 @@ class TaskRepository extends BaseRepository
$log = array_merge($log, [[$start_time, 0]]); $log = array_merge($log, [[$start_time, 0]]);
$task->time_log = json_encode($log); $task->time_log = json_encode($log);
$task->calculated_start_date = \Carbon\Carbon::createFromTimestamp($start_time); $task->calculated_start_date = \Carbon\Carbon::createFromTimestamp($start_time)->addSeconds($task->company->utc_offset());
$task->saveQuietly(); $task->saveQuietly();
} }