Merge pull request #2418 from CachetHQ/dates

Switch back to jenseggers/date
This commit is contained in:
James Brooks 2017-03-09 19:44:15 +00:00 committed by GitHub
commit e9e3115665
11 changed files with 140 additions and 72 deletions

View File

@ -14,9 +14,9 @@ namespace CachetHQ\Cachet\Foundation\Providers;
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.
@ -67,7 +67,7 @@ class ConfigServiceProvider extends ServiceProvider
if ($appLocale = $this->app->config->get('setting.app_locale')) {
$this->app->config->set('app.locale', $appLocale);
$this->app->translator->setLocale($appLocale);
Carbon::setLocale($appLocale);
Date::setLocale($appLocale);
}
// Set the timezone.

View File

@ -17,12 +17,12 @@ use CachetHQ\Cachet\Models\Component;
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.
@ -34,7 +34,7 @@ class DashboardController extends Controller
/**
* Start date.
*
* @var \Carbon\Carbon
* @var \Jenssegers\Date\Date
*/
protected $startDate;
@ -71,7 +71,7 @@ class DashboardController extends Controller
{
$this->feed = $feed;
$this->guard = $guard;
$this->startDate = Carbon::now();
$this->startDate = new Date();
$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->format('Y-m-d').' 23:59:59',
])->orderBy('occurred_at', 'desc')->get()->groupBy(function (Incident $incident) {
return (new Carbon($incident->occurred_at))
return (new Date($incident->occurred_at))
->setTimezone($this->dateTimeZone)->toDateString();
});
// Add in days that have no incidents
foreach (range(0, 30) as $i) {
$date = (new Carbon($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
$date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
if (!isset($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->format('Y-m-d').' 23:59:59',
])->orderBy('created_at', 'desc')->get()->groupBy(function (Subscriber $incident) {
return (new Carbon($incident->created_at))
return (new Date($incident->created_at))
->setTimezone($this->dateTimeZone)->toDateString();
});
// Add in days that have no incidents
foreach (range(0, 30) as $i) {
$date = (new Carbon($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
$date = (new Date($this->startDate))->setTimezone($this->dateTimeZone)->subDays($i);
if (!isset($allSubscribers[$date->toDateString()])) {
$allSubscribers[$date->toDateString()] = [];

View File

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

View File

@ -12,10 +12,10 @@
namespace CachetHQ\Cachet\Http\Middleware;
use CachetHQ\Cachet\Settings\Repository as SettingsRepository;
use Carbon\Carbon;
use Closure;
use Illuminate\Contracts\Config\Repository as ConfigRepository;
use Illuminate\Http\Request;
use Jenssegers\Date\Date;
/**
* This is the localize middleware class.
@ -82,7 +82,7 @@ class Localize
}
app('translator')->setLocale($userLanguage);
Carbon::setLocale($userLanguage);
Date::setLocale($userLanguage);
return $next($request);
}

View File

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

View File

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

View File

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

View File

@ -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')) {
/**
@ -47,7 +47,7 @@ if (!function_exists('formatted_date')) {
{
$dateFormat = Config::get('setting.date_format', 'jS F Y');
return Carbon::parse($date)->format($dateFormat);
return (new Date($date))->format($dateFormat);
}
}

View File

@ -44,6 +44,7 @@
"graham-campbell/exceptions": "^9.1",
"graham-campbell/markdown": "^7.1",
"guzzlehttp/guzzle": "^6.2.1",
"jenssegers/date": "^3.2",
"laravel/framework": "5.3.*",
"mccool/laravel-auto-presenter": "^4.3",
"nexmo/client": "@beta",

164
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically"
],
"content-hash": "43c85ea04920842652d64b760f121486",
"content-hash": "474ba4ec57ff312331ea84dcb517a83c",
"packages": [
{
"name": "alt-three/badger",
@ -449,22 +449,22 @@
},
{
"name": "aws/aws-sdk-php",
"version": "3.23.1",
"version": "3.24.0",
"source": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-php.git",
"reference": "7d319413995f9326e7aa41e02bcc799490038deb"
"reference": "3aacac064f40fcfdf8ecde2102a73d18b8b744d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/7d319413995f9326e7aa41e02bcc799490038deb",
"reference": "7d319413995f9326e7aa41e02bcc799490038deb",
"url": "https://api.github.com/repos/aws/aws-sdk-php/zipball/3aacac064f40fcfdf8ecde2102a73d18b8b744d0",
"reference": "3aacac064f40fcfdf8ecde2102a73d18b8b744d0",
"shasum": ""
},
"require": {
"guzzlehttp/guzzle": "^5.3.1|^6.2.1",
"guzzlehttp/promises": "~1.0",
"guzzlehttp/psr7": "~1.3.1",
"guzzlehttp/psr7": "^1.3.1, !=1.4.0",
"mtdowling/jmespath.php": "~2.2",
"php": ">=5.5"
},
@ -525,7 +525,7 @@
"s3",
"sdk"
],
"time": "2017-02-28T03:16:27+00:00"
"time": "2017-03-08T23:57:18+00:00"
},
{
"name": "backup-manager/backup-manager",
@ -1719,21 +1719,21 @@
},
{
"name": "guzzlehttp/guzzle",
"version": "6.2.2",
"version": "6.2.3",
"source": {
"type": "git",
"url": "https://github.com/guzzle/guzzle.git",
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60"
"reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
"reference": "ebf29dee597f02f09f4d5bbecc68230ea9b08f60",
"url": "https://api.github.com/repos/guzzle/guzzle/zipball/8d6c6cc55186db87b7dc5009827429ba4e9dc006",
"reference": "8d6c6cc55186db87b7dc5009827429ba4e9dc006",
"shasum": ""
},
"require": {
"guzzlehttp/promises": "^1.0",
"guzzlehttp/psr7": "^1.3.1",
"guzzlehttp/psr7": "^1.4",
"php": ">=5.5"
},
"require-dev": {
@ -1777,7 +1777,7 @@
"rest",
"web service"
],
"time": "2016-10-08T15:01:37+00:00"
"time": "2017-02-28T22:50:30+00:00"
},
{
"name": "guzzlehttp/promises",
@ -1832,16 +1832,16 @@
},
{
"name": "guzzlehttp/psr7",
"version": "1.3.1",
"version": "1.4.1",
"source": {
"type": "git",
"url": "https://github.com/guzzle/psr7.git",
"reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b"
"reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
"reference": "5c6447c9df362e8f8093bda8f5d8873fe5c7f65b",
"url": "https://api.github.com/repos/guzzle/psr7/zipball/0d6c7ca039329247e4f0f8f8f6506810e8248855",
"reference": "0d6c7ca039329247e4f0f8f8f6506810e8248855",
"shasum": ""
},
"require": {
@ -1877,16 +1877,23 @@
"name": "Michael Dowling",
"email": "mtdowling@gmail.com",
"homepage": "https://github.com/mtdowling"
},
{
"name": "Tobias Schultze",
"homepage": "https://github.com/Tobion"
}
],
"description": "PSR-7 message implementation",
"description": "PSR-7 message implementation that also provides common utility methods",
"keywords": [
"http",
"message",
"request",
"response",
"stream",
"uri"
"uri",
"url"
],
"time": "2016-06-24T23:00:38+00:00"
"time": "2017-02-27T10:51:17+00:00"
},
{
"name": "jakub-onderka/php-console-color",
@ -1975,6 +1982,63 @@
],
"time": "2015-04-20T18:58:01+00:00"
},
{
"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-02T09:21:15+00:00"
},
{
"name": "jeremeamia/SuperClosure",
"version": "2.3.0",
@ -2711,16 +2775,16 @@
},
{
"name": "nikic/php-parser",
"version": "v3.0.4",
"version": "v3.0.5",
"source": {
"type": "git",
"url": "https://github.com/nikic/PHP-Parser.git",
"reference": "0bf561dfe75ba80441c22adecc0529056671a7d2"
"reference": "2b9e2f71b722f7c53918ab0c25f7646c2013f17d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/0bf561dfe75ba80441c22adecc0529056671a7d2",
"reference": "0bf561dfe75ba80441c22adecc0529056671a7d2",
"url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/2b9e2f71b722f7c53918ab0c25f7646c2013f17d",
"reference": "2b9e2f71b722f7c53918ab0c25f7646c2013f17d",
"shasum": ""
},
"require": {
@ -2758,7 +2822,7 @@
"parser",
"php"
],
"time": "2017-02-10T20:20:03+00:00"
"time": "2017-03-05T18:23:57+00:00"
},
{
"name": "paragonie/random_compat",
@ -3606,16 +3670,16 @@
},
{
"name": "symfony/event-dispatcher",
"version": "v3.2.4",
"version": "v3.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "9137eb3a3328e413212826d63eeeb0217836e2b6"
"reference": "b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9137eb3a3328e413212826d63eeeb0217836e2b6",
"reference": "9137eb3a3328e413212826d63eeeb0217836e2b6",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d",
"reference": "b7a1b9e0a0f623ce43b4c8d775eb138f190c9d8d",
"shasum": ""
},
"require": {
@ -3662,7 +3726,7 @@
],
"description": "Symfony EventDispatcher Component",
"homepage": "https://symfony.com",
"time": "2017-01-02T20:32:22+00:00"
"time": "2017-02-21T09:12:04+00:00"
},
{
"name": "symfony/finder",
@ -4549,16 +4613,16 @@
},
{
"name": "filp/whoops",
"version": "2.1.7",
"version": "2.1.8",
"source": {
"type": "git",
"url": "https://github.com/filp/whoops.git",
"reference": "1a8192deae1f35aabc3a73aad19cd07c68091dd1"
"reference": "f2950be7da8b8d6c4e77821b6c9d486e36cdc4f3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/filp/whoops/zipball/1a8192deae1f35aabc3a73aad19cd07c68091dd1",
"reference": "1a8192deae1f35aabc3a73aad19cd07c68091dd1",
"url": "https://api.github.com/repos/filp/whoops/zipball/f2950be7da8b8d6c4e77821b6c9d486e36cdc4f3",
"reference": "f2950be7da8b8d6c4e77821b6c9d486e36cdc4f3",
"shasum": ""
},
"require": {
@ -4606,7 +4670,7 @@
"whoops",
"zf2"
],
"time": "2017-03-02T16:54:56+00:00"
"time": "2017-03-07T09:04:45+00:00"
},
{
"name": "fzaninotto/faker",
@ -5982,16 +6046,16 @@
},
{
"name": "symfony/css-selector",
"version": "v3.2.4",
"version": "v3.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/css-selector.git",
"reference": "f0e628f04fc055c934b3211cfabdb1c59eefbfaa"
"reference": "a48f13dc83c168f1253a5d2a5a4fb46c36244c4c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/f0e628f04fc055c934b3211cfabdb1c59eefbfaa",
"reference": "f0e628f04fc055c934b3211cfabdb1c59eefbfaa",
"url": "https://api.github.com/repos/symfony/css-selector/zipball/a48f13dc83c168f1253a5d2a5a4fb46c36244c4c",
"reference": "a48f13dc83c168f1253a5d2a5a4fb46c36244c4c",
"shasum": ""
},
"require": {
@ -6031,20 +6095,20 @@
],
"description": "Symfony CssSelector Component",
"homepage": "https://symfony.com",
"time": "2017-01-02T20:32:22+00:00"
"time": "2017-02-21T09:12:04+00:00"
},
{
"name": "symfony/dom-crawler",
"version": "v3.2.4",
"version": "v3.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/dom-crawler.git",
"reference": "b814b41373fc4e535aff8c765abe39545216f391"
"reference": "403944e294cf4ceb3b8447f54cbad88ea7b99cee"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/b814b41373fc4e535aff8c765abe39545216f391",
"reference": "b814b41373fc4e535aff8c765abe39545216f391",
"url": "https://api.github.com/repos/symfony/dom-crawler/zipball/403944e294cf4ceb3b8447f54cbad88ea7b99cee",
"reference": "403944e294cf4ceb3b8447f54cbad88ea7b99cee",
"shasum": ""
},
"require": {
@ -6087,20 +6151,20 @@
],
"description": "Symfony DomCrawler Component",
"homepage": "https://symfony.com",
"time": "2017-01-21T17:14:11+00:00"
"time": "2017-02-21T09:12:04+00:00"
},
{
"name": "symfony/yaml",
"version": "v3.2.4",
"version": "v3.2.5",
"source": {
"type": "git",
"url": "https://github.com/symfony/yaml.git",
"reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8"
"reference": "093e416ad096355149e265ea2e4cc1f9ee40ab1a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/yaml/zipball/9724c684646fcb5387d579b4bfaa63ee0b0c64c8",
"reference": "9724c684646fcb5387d579b4bfaa63ee0b0c64c8",
"url": "https://api.github.com/repos/symfony/yaml/zipball/093e416ad096355149e265ea2e4cc1f9ee40ab1a",
"reference": "093e416ad096355149e265ea2e4cc1f9ee40ab1a",
"shasum": ""
},
"require": {
@ -6142,7 +6206,7 @@
],
"description": "Symfony Yaml Component",
"homepage": "https://symfony.com",
"time": "2017-02-16T22:46:52+00:00"
"time": "2017-03-07T16:47:02+00:00"
},
{
"name": "tightenco/mailthief",

View File

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