Skip to content

Commit

Permalink
added date class
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Mar 25, 2020
1 parent ee6041e commit 201a369
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 15 deletions.
2 changes: 1 addition & 1 deletion app/Abstracts/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Abstracts;

use App\Utilities\Date;
use Illuminate\Support\Str;
use Jenssegers\Date\Date;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
use Maatwebsite\Excel\Concerns\WithHeadings;
Expand Down
2 changes: 1 addition & 1 deletion app/Abstracts/Import.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace App\Abstracts;

use App\Traits\Import as ImportHelper;
use App\Utilities\Date;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Jenssegers\Date\Date;
use Maatwebsite\Excel\Concerns\Importable;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\SkipsOnError;
Expand Down
2 changes: 1 addition & 1 deletion app/Abstracts/Widget.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace App\Abstracts;

use App\Traits\Charts;
use Date;
use App\Utilities\Date;

abstract class Widget
{
Expand Down
8 changes: 4 additions & 4 deletions app/Listeners/Auth/Login.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App\Listeners\Auth;

use Date;
use App\Utilities\Date;
use Illuminate\Auth\Events\Login as ILogin;

class Login
Expand All @@ -18,13 +18,13 @@ public function handle(ILogin $event)
{
// Get first company
$company = $event->user->companies()->enabled()->first();

// Logout if no company assigned
if (!$company) {
app('App\Http\Controllers\Auth\Login')->logout();

flash(trans('auth.error.no_company'))->error();

return;
}

Expand Down
60 changes: 60 additions & 0 deletions app/Utilities/Date.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

namespace App\Utilities;

use Carbon\Carbon;

class Date extends Carbon
{
/**
* Function to call instead of format.
*
* @var string|callable|null
*/
protected static $formatFunction = 'translatedFormat';

/**
* Function to call instead of createFromFormat.
*
* @var string|callable|null
*/
protected static $createFromFormatFunction = 'createFromFormatWithCurrentLocale';

/**
* Function to call instead of parse.
*
* @var string|callable|null
*/
protected static $parseFunction = 'parseWithCurrentLocale';

public static function parseWithCurrentLocale($time = null, $timezone = null)
{
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
}

return parent::rawParse($time, $timezone);
}

public static function createFromFormatWithCurrentLocale($format, $time = null, $timezone = null)
{
if (is_string($time)) {
$time = static::translateTimeString($time, static::getLocale(), 'en');
}

return parent::rawCreateFromFormat($format, $time, $timezone);
}

/**
* Get the language portion of the locale.
*
* @param string $locale
* @return string
*/
public static function getLanguageFromLocale($locale)
{
$parts = explode('_', str_replace('-', '_', $locale));

return $parts[0];
}
}
2 changes: 1 addition & 1 deletion app/Utilities/helpers.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php

use App\Traits\DateTime;
use App\Utilities\Date;
use App\Utilities\Widgets;
use Jenssegers\Date\Date;

if (!function_exists('user')) {
/**
Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
"graham-campbell/markdown": "12.0.*",
"guzzlehttp/guzzle": "^6.5",
"intervention/image": "2.5.*",
"jenssegers/date": "4.0.0-beta",
"kyslik/column-sortable": "^6.0",
"laracasts/flash": "3.1.*",
"laravel/framework": "^7.0",
Expand Down
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@
'Config' => Illuminate\Support\Facades\Config::class,
'Cookie' => Illuminate\Support\Facades\Cookie::class,
'Crypt' => Illuminate\Support\Facades\Crypt::class,
'Date' => App\Utilities\Date::class,
'DB' => Illuminate\Support\Facades\DB::class,
'Eloquent' => Illuminate\Database\Eloquent\Model::class,
'Event' => Illuminate\Support\Facades\Event::class,
Expand Down
2 changes: 1 addition & 1 deletion config/language.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
| This option the language of jenssegers/date library.
|
*/
'date' => true,
'date' => false,

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions database/factories/Bill.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Purchase\Bill;
use Faker\Generator as Faker;
use Jenssegers\Date\Date;
use App\Models\Setting\Tax;
use App\Utilities\Date;
use Faker\Generator as Faker;

$user = User::first();
$company = $user->companies()->first();
Expand Down
2 changes: 1 addition & 1 deletion database/factories/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
use App\Models\Common\Item;
use App\Models\Sale\Invoice;
use App\Models\Setting\Tax;
use App\Utilities\Date;
use Faker\Generator as Faker;
use Jenssegers\Date\Date;

$user = User::first();
$company = $user->companies()->first();
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Commands/BillReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use App\Jobs\Purchase\CreateBill;
use App\Models\Purchase\Bill;
use App\Notifications\Purchase\Bill as BillNotification;
use App\Utilities\Date;
use Illuminate\Support\Facades\Notification as Notification;
use Jenssegers\Date\Date;
use Tests\Feature\FeatureTestCase;

class BillReminderTest extends FeatureTestCase
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/Commands/InvoiceReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
use App\Jobs\Sale\CreateInvoice;
use App\Models\Sale\Invoice;
use App\Notifications\Sale\Invoice as InvoiceNotification;
use App\Utilities\Date;
use Illuminate\Support\Facades\Notification;
use Jenssegers\Date\Date;
use Tests\Feature\FeatureTestCase;

class InvoiceReminderTest extends FeatureTestCase
Expand Down

0 comments on commit 201a369

Please sign in to comment.