Remove jenssegers/date and solely use Carbon

This commit is contained in:
James Brooks
2017-01-02 16:11:15 +00:00
parent a2bbb18f79
commit 2b75eca7d0
11 changed files with 25 additions and 86 deletions

View File

@@ -11,8 +11,8 @@
namespace CachetHQ\Cachet\Dates; namespace CachetHQ\Cachet\Dates;
use Carbon\Carbon;
use DateTimeZone; use DateTimeZone;
use Jenssegers\Date\Date;
/** /**
* This is the date factory class. * This is the date factory class.
@@ -62,7 +62,7 @@ class DateFactory
*/ */
public function create($format, $time) public function create($format, $time)
{ {
return Date::createFromFormat($format, $time, $this->cachetTimezone)->setTimezone($this->appTimezone); return Carbon::createFromFormat($format, $time, $this->cachetTimezone)->setTimezone($this->appTimezone);
} }
/** /**
@@ -79,7 +79,7 @@ class DateFactory
*/ */
public function createNormalized($format, $time) public function createNormalized($format, $time)
{ {
return Date::createFromFormat($format, $time)->setTimezone($this->appTimezone); return Carbon::createFromFormat($format, $time)->setTimezone($this->appTimezone);
} }
/** /**
@@ -93,7 +93,7 @@ class DateFactory
*/ */
public function make($time = null) public function make($time = null)
{ {
return (new Date($time))->setTimezone($this->cachetTimezone); return Carbon::parse($time)->setTimezone($this->cachetTimezone);
} }
/** /**
@@ -103,7 +103,7 @@ class DateFactory
*/ */
public function getTimezone() public function getTimezone()
{ {
$dateTime = new Date(); $dateTime = new Carbon();
$dateTime->setTimeZone(new DateTimeZone($this->cachetTimezone)); $dateTime->setTimeZone(new DateTimeZone($this->cachetTimezone));
return $dateTime->format('T'); return $dateTime->format('T');

View File

@@ -14,9 +14,9 @@ namespace CachetHQ\Cachet\Foundation\Providers;
use CachetHQ\Cachet\Models\Setting as SettingModel; use CachetHQ\Cachet\Models\Setting as SettingModel;
use CachetHQ\Cachet\Settings\Cache; use CachetHQ\Cachet\Settings\Cache;
use CachetHQ\Cachet\Settings\Repository; use CachetHQ\Cachet\Settings\Repository;
use Carbon\Carbon;
use Exception; use Exception;
use Illuminate\Support\ServiceProvider; use Illuminate\Support\ServiceProvider;
use Jenssegers\Date\Date;
/** /**
* This is the config service provider class. * This is the config service provider class.
@@ -65,7 +65,7 @@ class ConfigServiceProvider extends ServiceProvider
if ($appLocale = $this->app->config->get('setting.app_locale')) { if ($appLocale = $this->app->config->get('setting.app_locale')) {
$this->app->config->set('app.locale', $appLocale); $this->app->config->set('app.locale', $appLocale);
$this->app->translator->setLocale($appLocale); $this->app->translator->setLocale($appLocale);
Date::setLocale($appLocale); Carbon::setLocale($appLocale);
} }
if ($appTimezone = $this->app->config->get('setting.app_timezone')) { if ($appTimezone = $this->app->config->get('setting.app_timezone')) {

View File

@@ -17,12 +17,12 @@ use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\ComponentGroup; use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident; use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Subscriber; use CachetHQ\Cachet\Models\Subscriber;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\Guard; use Illuminate\Contracts\Auth\Guard;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
/** /**
* This is the dashboard controller class. * This is the dashboard controller class.
@@ -34,7 +34,7 @@ class DashboardController extends Controller
/** /**
* Start date. * Start date.
* *
* @var \Jenssegers\Date\Date * @var \Carbon\Carbon
*/ */
protected $startDate; protected $startDate;
@@ -71,7 +71,7 @@ class DashboardController extends Controller
{ {
$this->feed = $feed; $this->feed = $feed;
$this->guard = $guard; $this->guard = $guard;
$this->startDate = new Date(); $this->startDate = Carbon::now();
$this->dateTimeZone = Config::get('cachet.timezone'); $this->dateTimeZone = Config::get('cachet.timezone');
} }
@@ -131,13 +131,13 @@ class DashboardController extends Controller
$this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00', $this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00',
$this->startDate->format('Y-m-d').' 23:59:59', $this->startDate->format('Y-m-d').' 23:59:59',
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) { ])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
return (new Date($incident->occurred_at)) return (new Carbon($incident->occurred_at))
->setTimezone($this->dateTimeZone)->toDateString(); ->setTimezone($this->dateTimeZone)->toDateString();
}); });
// Add in days that have no incidents // Add in days that have no incidents
foreach (range(0, 30) as $i) { foreach (range(0, 30) as $i) {
$date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i); $date = (new Carbon($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
if (!isset($allIncidents[$date->toDateString()])) { if (!isset($allIncidents[$date->toDateString()])) {
$allIncidents[$date->toDateString()] = []; $allIncidents[$date->toDateString()] = [];
@@ -163,13 +163,13 @@ class DashboardController extends Controller
$this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00', $this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00',
$this->startDate->format('Y-m-d').' 23:59:59', $this->startDate->format('Y-m-d').' 23:59:59',
])->orderBy('created_at', 'desc')->get()->groupBy(function (Subscriber $incident) { ])->orderBy('created_at', 'desc')->get()->groupBy(function (Subscriber $incident) {
return (new Date($incident->created_at)) return (new Carbon($incident->created_at))
->setTimezone($this->dateTimeZone)->toDateString(); ->setTimezone($this->dateTimeZone)->toDateString();
}); });
// Add in days that have no incidents // Add in days that have no incidents
foreach (range(0, 30) as $i) { foreach (range(0, 30) as $i) {
$date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i); $date = (new Carbon($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
if (!isset($allSubscribers[$date->toDateString()])) { if (!isset($allSubscribers[$date->toDateString()])) {
$allSubscribers[$date->toDateString()] = []; $allSubscribers[$date->toDateString()] = [];

View File

@@ -19,6 +19,7 @@ use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\Schedule; use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Cachet\Repositories\Metric\MetricRepository; use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
use Carbon\Carbon;
use Exception; use Exception;
use GrahamCampbell\Binput\Facades\Binput; use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller; use Illuminate\Routing\Controller;
@@ -26,7 +27,6 @@ use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Response; use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\View; use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter; use McCool\LaravelAutoPresenter\Facades\AutoPresenter;
/** /**
@@ -45,14 +45,14 @@ class StatusPageController extends AbstractApiController
*/ */
public function showIndex() public function showIndex()
{ {
$today = Date::now(); $today = Carbon::now();
$startDate = Date::now(); $startDate = Carbon::now();
// Check if we have another starting date // Check if we have another starting date
if (Binput::has('start_date')) { if (Binput::has('start_date')) {
try { try {
// If date provided is valid // If date provided is valid
$oldDate = Date::createFromFormat('Y-m-d', Binput::get('start_date')); $oldDate = Carbon::createFromFormat('Y-m-d', Binput::get('start_date'));
// If trying to get a future date fallback to today // If trying to get a future date fallback to today
if ($today->gt($oldDate)) { if ($today->gt($oldDate)) {

View File

@@ -11,10 +11,10 @@
namespace CachetHQ\Cachet\Http\Middleware; namespace CachetHQ\Cachet\Http\Middleware;
use Carbon\Carbon;
use Closure; use Closure;
use Illuminate\Config\Repository; use Illuminate\Config\Repository;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Jenssegers\Date\Date;
/** /**
* This is the localize middleware class. * This is the localize middleware class.
@@ -28,7 +28,7 @@ class Localize
/** /**
* Array of languages Cachet can use. * Array of languages Cachet can use.
* *
* @var array * @var string[]
*/ */
protected $langs; protected $langs;
@@ -79,7 +79,7 @@ class Localize
} }
app('translator')->setLocale($userLanguage); app('translator')->setLocale($userLanguage);
Date::setLocale($userLanguage); Carbon::setLocale($userLanguage);
return $next($request); return $next($request);
} }

View File

@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
/** /**
* This is the pgsql repository class. * This is the pgsql repository class.

View File

@@ -13,7 +13,6 @@ namespace CachetHQ\Cachet\Repositories\Metric;
use CachetHQ\Cachet\Models\Metric; use CachetHQ\Cachet\Models\Metric;
use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;
/** /**
* This is the sqlite repository class. * This is the sqlite repository class.

View File

@@ -9,9 +9,9 @@
* file that was distributed with this source code. * file that was distributed with this source code.
*/ */
use Carbon\Carbon;
use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request; use Illuminate\Support\Facades\Request;
use Jenssegers\Date\Date;
if (!function_exists('set_active')) { if (!function_exists('set_active')) {
/** /**
@@ -47,7 +47,7 @@ if (!function_exists('formatted_date')) {
{ {
$dateFormat = Config::get('setting.date_format', 'jS F Y'); $dateFormat = Config::get('setting.date_format', 'jS F Y');
return (new Date($date))->format($dateFormat); return Carbon::parse($date)->format($dateFormat);
} }
} }

View File

@@ -43,7 +43,6 @@
"graham-campbell/exceptions": "^9.1", "graham-campbell/exceptions": "^9.1",
"graham-campbell/markdown": "^6.1", "graham-campbell/markdown": "^6.1",
"guzzlehttp/guzzle": "^6.2.1", "guzzlehttp/guzzle": "^6.2.1",
"jenssegers/date": "^3.2",
"laravel/framework": "5.3.*", "laravel/framework": "5.3.*",
"mccool/laravel-auto-presenter": "^4.3", "mccool/laravel-auto-presenter": "^4.3",
"pragmarx/google2fa": "^0.7.1", "pragmarx/google2fa": "^0.7.1",

61
composer.lock generated
View File

@@ -4,8 +4,8 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"hash": "fca8fc5b2e78a82f98a0bfa85672b87f", "hash": "8a12e392376c66089b5435df09154936",
"content-hash": "d60fff17875690a829a28ad77b35e68d", "content-hash": "4da236537bf5c691b4297b065c6669eb",
"packages": [ "packages": [
{ {
"name": "alt-three/badger", "name": "alt-three/badger",
@@ -1903,63 +1903,6 @@
], ],
"time": "2015-04-20 18:58:01" "time": "2015-04-20 18:58:01"
}, },
{
"name": "jenssegers/date",
"version": "v3.2.8",
"source": {
"type": "git",
"url": "https://github.com/jenssegers/date.git",
"reference": "ad55257ae655af540e055c0fcd48bc3ec1962ec4"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/jenssegers/date/zipball/ad55257ae655af540e055c0fcd48bc3ec1962ec4",
"reference": "ad55257ae655af540e055c0fcd48bc3ec1962ec4",
"shasum": ""
},
"require": {
"nesbot/carbon": "^1.0",
"php": ">=5.4",
"symfony/translation": "^2.7|^3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.0|^5.0",
"satooshi/php-coveralls": "^1.0"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "3.1-dev"
}
},
"autoload": {
"psr-4": {
"Jenssegers\\Date\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Jens Segers",
"homepage": "https://jenssegers.com"
}
],
"description": "A date library to help you work with dates in different languages",
"homepage": "https://github.com/jenssegers/date",
"keywords": [
"carbon",
"date",
"datetime",
"i18n",
"laravel",
"time",
"translation"
],
"time": "2017-01-02 09:21:15"
},
{ {
"name": "jeremeamia/SuperClosure", "name": "jeremeamia/SuperClosure",
"version": "2.3.0", "version": "2.3.0",

View File

@@ -184,7 +184,6 @@ return [
'GrahamCampbell\Core\CoreServiceProvider', 'GrahamCampbell\Core\CoreServiceProvider',
'GrahamCampbell\Markdown\MarkdownServiceProvider', 'GrahamCampbell\Markdown\MarkdownServiceProvider',
'GrahamCampbell\Security\SecurityServiceProvider', 'GrahamCampbell\Security\SecurityServiceProvider',
'Jenssegers\Date\DateServiceProvider',
'McCool\LaravelAutoPresenter\AutoPresenterServiceProvider', 'McCool\LaravelAutoPresenter\AutoPresenterServiceProvider',
'PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider', 'PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider',
'Roumen\Feed\FeedServiceProvider', 'Roumen\Feed\FeedServiceProvider',