Fix timezones presenting

This commit is contained in:
Joseph Cohen
2015-01-27 13:05:54 -06:00
parent 04d9ce6b80
commit 900b15a808
3 changed files with 25 additions and 8 deletions

View File

@@ -5,6 +5,7 @@ namespace CachetHQ\Cachet\Http\Controllers;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Component;
use CachetHQ\Cachet\Models\Incident;
use Carbon\Carbon;
use Exception;
use GrahamCampbell\Binput\Facades\Binput;
use GrahamCampbell\Markdown\Facades\Markdown;
@@ -27,8 +28,8 @@ class HomeController extends Controller
$incidentDays = Setting::get('app_incident_days') ?: 7;
$today = Date::now();
$startDate = Date::now();
$today = Carbon::now();
$startDate = Carbon::now();
$dateFormat = Setting::get('date_format') ?: 'jS F Y';
@@ -48,11 +49,16 @@ class HomeController extends Controller
foreach (range(0, $incidentDays) as $i) {
$date = $startDate->copy()->subDays($i);
$incidents = Incident::whereBetween('created_at', [
$date->format('Y-m-d').' 00:00:00',
$date->format('Y-m-d').' 23:59:59',
])->orderBy('created_at', 'desc')->get();
$allIncidents[] = ['date' => $date->format($dateFormat), 'incidents' => $incidents];
$allIncidents[] = [
'date' => (new Date($date->toDateTimeString()))->format($dateFormat),
'incidents' => $incidents,
];
}
return View::make('index', [

View File

@@ -2,12 +2,20 @@
namespace CachetHQ\Cachet\Presenters;
use CachetHQ\Cachet\Facades\Setting;
use CachetHQ\Cachet\Models\Incident;
use Jenssegers\Date\Date;
use McCool\LaravelAutoPresenter\BasePresenter;
class IncidentPresenter extends BasePresenter
{
/**
* Time zone setting.
*
* @var string
*/
protected $tz;
/**
* Create a incident presenter instance.
*
@@ -16,6 +24,7 @@ class IncidentPresenter extends BasePresenter
public function __construct(Incident $incident)
{
$this->resource = $incident;
$this->tz = Setting::get('app_timezone');
}
/**
@@ -25,7 +34,9 @@ class IncidentPresenter extends BasePresenter
*/
public function created_at_diff()
{
return (new Date($this->resource->created_at))->diffForHumans();
return (new Date($this->resource->created_at))
->setTimezone($this->tz)
->diffForHumans();
}
/**
@@ -35,7 +46,9 @@ class IncidentPresenter extends BasePresenter
*/
public function created_at_formated()
{
return ucfirst((new Date($this->resource->created_at))->format('l j F Y H:i:s'));
return ucfirst((new Date($this->resource->created_at))
->setTimezone($this->tz)
->format('l j F Y H:i:s'));
}
/**
@@ -45,6 +58,6 @@ class IncidentPresenter extends BasePresenter
*/
public function created_at_iso()
{
return $this->resource->created_at->toISO8601String();
return $this->resource->created_at->setTimezone($this->tz)->toISO8601String();
}
}

View File

@@ -20,7 +20,6 @@ class LoadConfigServiceProvider extends ServiceProvider
try {
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appTimezone = Setting::get('app_timezone');
$appLocale = Setting::get('app_locale');
} catch (QueryException $e) {
// Don't throw any errors, we may not be setup yet.
@@ -28,7 +27,6 @@ class LoadConfigServiceProvider extends ServiceProvider
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$this->app->config->set('app.timezone', $appTimezone ?: $this->app->config->get('app.timezone'));
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
// Set custom lang.