Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solely use Carbon #2289

Merged
merged 1 commit into from
Jan 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions app/Dates/DateFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace CachetHQ\Cachet\Dates;

use Carbon\Carbon;
use DateTimeZone;
use Jenssegers\Date\Date;

/**
* This is the date factory class.
Expand Down Expand Up @@ -62,7 +62,7 @@ public function __construct($appTimezone, $cachetTimezone)
*/
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);
}

/**
Expand All @@ -79,7 +79,7 @@ public function create($format, $time)
*/
public function createNormalized($format, $time)
{
return Date::createFromFormat($format, $time)->setTimezone($this->appTimezone);
return Carbon::createFromFormat($format, $time)->setTimezone($this->appTimezone);
}

/**
Expand All @@ -93,7 +93,7 @@ public function createNormalized($format, $time)
*/
public function make($time = null)
{
return (new Date($time))->setTimezone($this->cachetTimezone);
return Carbon::parse($time)->setTimezone($this->cachetTimezone);
}

/**
Expand All @@ -103,7 +103,7 @@ public function make($time = null)
*/
public function getTimezone()
{
$dateTime = new Date();
$dateTime = new Carbon();
$dateTime->setTimeZone(new DateTimeZone($this->cachetTimezone));

return $dateTime->format('T');
Expand Down
4 changes: 2 additions & 2 deletions app/Foundation/Providers/ConfigServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
use CachetHQ\Cachet\Models\Setting as SettingModel;
use CachetHQ\Cachet\Settings\Cache;
use CachetHQ\Cachet\Settings\Repository;
use Carbon\Carbon;
use Exception;
use Illuminate\Support\ServiceProvider;
use Jenssegers\Date\Date;

/**
* This is the config service provider class.
Expand Down Expand Up @@ -65,7 +65,7 @@ public function boot()
if ($appLocale = $this->app->config->get('setting.app_locale')) {
$this->app->config->set('app.locale', $appLocale);
$this->app->translator->setLocale($appLocale);
Date::setLocale($appLocale);
Carbon::setLocale($appLocale);
}

if ($appTimezone = $this->app->config->get('setting.app_timezone')) {
Expand Down
14 changes: 7 additions & 7 deletions app/Http/Controllers/Dashboard/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
use CachetHQ\Cachet\Models\ComponentGroup;
use CachetHQ\Cachet\Models\Incident;
use CachetHQ\Cachet\Models\Subscriber;
use Carbon\Carbon;
use Illuminate\Contracts\Auth\Guard;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;

/**
* This is the dashboard controller class.
Expand All @@ -34,7 +34,7 @@ class DashboardController extends Controller
/**
* Start date.
*
* @var \Jenssegers\Date\Date
* @var \Carbon\Carbon
*/
protected $startDate;

Expand Down Expand Up @@ -71,7 +71,7 @@ public function __construct(Feed $feed, Guard $guard)
{
$this->feed = $feed;
$this->guard = $guard;
$this->startDate = new Date();
$this->startDate = Carbon::now();
$this->dateTimeZone = Config::get('cachet.timezone');
}

Expand Down Expand Up @@ -131,13 +131,13 @@ protected function getIncidents()
$this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00',
$this->startDate->format('Y-m-d').' 23:59:59',
])->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();
});

// Add in days that have no incidents
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()])) {
$allIncidents[$date->toDateString()] = [];
Expand All @@ -163,13 +163,13 @@ protected function getSubscribers()
$this->startDate->copy()->subDays(30)->format('Y-m-d').' 00:00:00',
$this->startDate->format('Y-m-d').' 23:59:59',
])->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();
});

// Add in days that have no incidents
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()])) {
$allSubscribers[$date->toDateString()] = [];
Expand Down
8 changes: 4 additions & 4 deletions app/Http/Controllers/StatusPageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
use CachetHQ\Cachet\Models\Metric;
use CachetHQ\Cachet\Models\Schedule;
use CachetHQ\Cachet\Repositories\Metric\MetricRepository;
use Carbon\Carbon;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\View;
use Jenssegers\Date\Date;
use McCool\LaravelAutoPresenter\Facades\AutoPresenter;

/**
Expand All @@ -45,14 +45,14 @@ class StatusPageController extends AbstractApiController
*/
public function showIndex()
{
$today = Date::now();
$startDate = Date::now();
$today = Carbon::now();
$startDate = Carbon::now();

// Check if we have another starting date
if (Binput::has('start_date')) {
try {
// 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 ($today->gt($oldDate)) {
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Middleware/Localize.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@

namespace CachetHQ\Cachet\Http\Middleware;

use Carbon\Carbon;
use Closure;
use Illuminate\Config\Repository;
use Illuminate\Http\Request;
use Jenssegers\Date\Date;

/**
* This is the localize middleware class.
Expand All @@ -28,7 +28,7 @@ class Localize
/**
* Array of languages Cachet can use.
*
* @var array
* @var string[]
*/
protected $langs;

Expand Down Expand Up @@ -79,7 +79,7 @@ public function handle(Request $request, Closure $next)
}

app('translator')->setLocale($userLanguage);
Date::setLocale($userLanguage);
Carbon::setLocale($userLanguage);

return $next($request);
}
Expand Down
1 change: 0 additions & 1 deletion app/Repositories/Metric/PgSqlRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use CachetHQ\Cachet\Models\Metric;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;

/**
* This is the pgsql repository class.
Expand Down
1 change: 0 additions & 1 deletion app/Repositories/Metric/SqliteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

use CachetHQ\Cachet\Models\Metric;
use Illuminate\Support\Facades\DB;
use Jenssegers\Date\Date;

/**
* This is the sqlite repository class.
Expand Down
4 changes: 2 additions & 2 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* file that was distributed with this source code.
*/

use Carbon\Carbon;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Request;
use Jenssegers\Date\Date;

if (!function_exists('set_active')) {
/**
Expand Down Expand Up @@ -47,7 +47,7 @@ function formatted_date($date)
{
$dateFormat = Config::get('setting.date_format', 'jS F Y');

return (new Date($date))->format($dateFormat);
return Carbon::parse($date)->format($dateFormat);
}
}

Expand Down
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
"graham-campbell/exceptions": "^9.1",
"graham-campbell/markdown": "^6.1",
"guzzlehttp/guzzle": "^6.2.1",
"jenssegers/date": "^3.2",
"laravel/framework": "5.3.*",
"mccool/laravel-auto-presenter": "^4.3",
"pragmarx/google2fa": "^0.7.1",
Expand Down
61 changes: 2 additions & 59 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,6 @@
'GrahamCampbell\Core\CoreServiceProvider',
'GrahamCampbell\Markdown\MarkdownServiceProvider',
'GrahamCampbell\Security\SecurityServiceProvider',
'Jenssegers\Date\DateServiceProvider',
'McCool\LaravelAutoPresenter\AutoPresenterServiceProvider',
'PragmaRX\Google2FA\Vendor\Laravel\ServiceProvider',
'Roumen\Feed\FeedServiceProvider',
Expand Down