1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-05 18:52:44 +01:00

Fixes for test

This commit is contained in:
David Bomba 2019-08-28 10:58:13 +10:00
parent 33b42db47c
commit 0af0d9786d
3 changed files with 39 additions and 4 deletions

View File

@ -16,12 +16,13 @@ use App\Http\Controllers\Controller;
use App\Jobs\Entity\ActionEntity;
use App\Models\Invoice;
use App\Repositories\BaseRepository;
use App\Utils\Traits\MakesDates;
use App\Utils\Traits\MakesHash;
use Barracuda\ArchiveStream\Archive;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Yajra\DataTables\Facades\DataTables;
use Yajra\DataTables\Html\Builder;
use Barracuda\ArchiveStream\Archive;
/**
* Class InvoiceController
@ -32,7 +33,7 @@ class InvoiceController extends Controller
{
use MakesHash;
use MakesDates;
/**
* Show the list of Invoices
*
@ -56,7 +57,7 @@ class InvoiceController extends Controller
return Invoice::badgeForStatus($invoice->status);
})
->editColumn('invoice_date', function ($invoice){
return
return $this->createClientDate($invoice->due_date, $invoice->client->timezone()->name)->format('MM-dd-YYYY');
})
->rawColumns(['checkbox', 'action', 'status_id'])
->make(true);

View File

@ -11,6 +11,8 @@
namespace App\Utils\Traits;
use Illuminate\Support\Facades\Log;
/**
* Class MakesDates
* @package App\Utils\Traits
@ -26,17 +28,36 @@ trait MakesDates
*/
public function createClientDate($utc_date , $timezone)
{
Log::error($utc_date. ' '. $timezone);
if(is_string($utc_date))
$utc_date = $this->convertToDateObject($utc_date);
return $utc_date->setTimezone(new \DateTimeZone($timezone));
}
/**
* Converts from client timezone to UTC
* @param datetime object $utc_date
* @param string $timezone ie Australia/Sydney
* @return Carbon Carbon object
*/
public function createUtcDate($client_date)
{
if(is_string($client_date))
$client_date = $this->convertToDateObject($client_date);
return $client_date->setTimezone(new \DateTimeZone('GMT'));
}
private function convertToDateObject($date)
{
return new \DateTime($date);
}
}

View File

@ -81,6 +81,19 @@ class MakesDatesTest extends TestCase
$this->assertEquals('2007-04-19 22:59', $client_date->format('Y-m-d H:i'));
}
public function testCreateClientDateWithFormat()
{
$client_date_src = '2007-04-19';
$client_timezone = 'Atlantic/Cape_Verde'; // -1 UTC
$date_time = new \DateTime($client_date_src, new \DateTimeZone($client_timezone));
$utc_date = $this->createUtcDate($date_time, $client_timezone);
$client_date = $this->createClientDate($utc_date, $client_timezone);
$this->assertEquals('2007-04-19', $client_date->format('Y-m-d'));
}
}