mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Fixes for test
This commit is contained in:
parent
33b42db47c
commit
0af0d9786d
@ -16,12 +16,13 @@ use App\Http\Controllers\Controller;
|
|||||||
use App\Jobs\Entity\ActionEntity;
|
use App\Jobs\Entity\ActionEntity;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Repositories\BaseRepository;
|
use App\Repositories\BaseRepository;
|
||||||
|
use App\Utils\Traits\MakesDates;
|
||||||
use App\Utils\Traits\MakesHash;
|
use App\Utils\Traits\MakesHash;
|
||||||
|
use Barracuda\ArchiveStream\Archive;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Yajra\DataTables\Facades\DataTables;
|
use Yajra\DataTables\Facades\DataTables;
|
||||||
use Yajra\DataTables\Html\Builder;
|
use Yajra\DataTables\Html\Builder;
|
||||||
use Barracuda\ArchiveStream\Archive;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class InvoiceController
|
* Class InvoiceController
|
||||||
@ -32,7 +33,7 @@ class InvoiceController extends Controller
|
|||||||
{
|
{
|
||||||
|
|
||||||
use MakesHash;
|
use MakesHash;
|
||||||
|
use MakesDates;
|
||||||
/**
|
/**
|
||||||
* Show the list of Invoices
|
* Show the list of Invoices
|
||||||
*
|
*
|
||||||
@ -56,7 +57,7 @@ class InvoiceController extends Controller
|
|||||||
return Invoice::badgeForStatus($invoice->status);
|
return Invoice::badgeForStatus($invoice->status);
|
||||||
})
|
})
|
||||||
->editColumn('invoice_date', function ($invoice){
|
->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'])
|
->rawColumns(['checkbox', 'action', 'status_id'])
|
||||||
->make(true);
|
->make(true);
|
||||||
|
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace App\Utils\Traits;
|
namespace App\Utils\Traits;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class MakesDates
|
* Class MakesDates
|
||||||
* @package App\Utils\Traits
|
* @package App\Utils\Traits
|
||||||
@ -26,17 +28,36 @@ trait MakesDates
|
|||||||
*/
|
*/
|
||||||
public function createClientDate($utc_date , $timezone)
|
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));
|
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)
|
public function createUtcDate($client_date)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
if(is_string($client_date))
|
||||||
|
$client_date = $this->convertToDateObject($client_date);
|
||||||
|
|
||||||
return $client_date->setTimezone(new \DateTimeZone('GMT'));
|
return $client_date->setTimezone(new \DateTimeZone('GMT'));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function convertToDateObject($date)
|
||||||
|
{
|
||||||
|
|
||||||
|
return new \DateTime($date);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -82,5 +82,18 @@ class MakesDatesTest extends TestCase
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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'));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user