Settable timezones with cachet config

This commit is contained in:
Joseph Cohen 2015-10-08 16:11:30 -05:00
parent ce8e710173
commit a288f84fc5
8 changed files with 32 additions and 7 deletions

View File

@ -40,7 +40,7 @@ class ReportIncidentCommandHandler
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
$incident->update([
'created_at' => $incidentDate,

View File

@ -30,7 +30,7 @@ class ReportMaintenanceCommandHandler
public function handle(ReportMaintenanceCommand $command)
{
// TODO: Add validation to scheduledAt
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, Setting::get('app_timezone'))
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, config('cachet.timezone'))
->setTimezone(Config::get('app.timezone'));
$maintenanceEvent = Incident::create([

View File

@ -35,7 +35,7 @@ class UpdateIncidentCommandHandler
// The incident occurred at a different time.
if ($command->incident_date) {
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, Setting::get('app_timezone'))->setTimezone(Config::get('app.timezone'));
$incidentDate = Date::createFromFormat('d/m/Y H:i', $command->incident_date, config('cachet.timezone'))->setTimezone(Config::get('app.timezone'));
$incident->update([
'created_at' => $incidentDate,

View File

@ -140,7 +140,7 @@ class ScheduleController extends Controller
{
$scheduleData = Binput::get('incident');
// Parse the schedule date.
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], Setting::get('app_timezone'))
$scheduledAt = Date::createFromFormat('d/m/Y H:i', $scheduleData['scheduled_at'], config('cachet.timezone'))
->setTimezone(Config::get('app.timezone'));
if ($scheduledAt->isPast()) {

View File

@ -55,7 +55,7 @@ class StatusPageController extends Controller
} else {
$incidentDays = range(0, $daysToShow);
}
$dateTimeZone = Setting::get('app_timezone');
$dateTimeZone = config('cachet.timezone');
$incidentVisiblity = Auth::check() ? 0 : 1;

View File

@ -28,8 +28,7 @@ class Timezone
public function handle($request, Closure $next)
{
if ($tz = $request->header('Time-Zone')) {
app('config')->set('app.timezone', $tz);
Setting::set('app_timezone', $tz);
app('config')->set('cachet.timezone', $tz);
}
return $next($request);

View File

@ -32,6 +32,7 @@ class ConfigServiceProvider extends ServiceProvider
// Get app custom configuration.
$appDomain = Setting::get('app_domain');
$appLocale = Setting::get('app_locale');
$appTimezone = Setting::get('app_timezone');
// Setup Cors.
$allowedOrigins = $this->app->config->get('cors.defaults.allowedOrigins');
@ -55,6 +56,7 @@ class ConfigServiceProvider extends ServiceProvider
// Override default app values.
$this->app->config->set('app.url', $appDomain ?: $this->app->config->get('app.url'));
$this->app->config->set('app.locale', $appLocale ?: $this->app->config->get('app.locale'));
$this->app->config->set('cachet.timezone', $appTimezone ?: $this->app->config->get('cachet.timezone'));
// Set custom lang.
$this->app->translator->setLocale($appLocale);

24
config/cachet.php Normal file
View File

@ -0,0 +1,24 @@
<?php
/*
* This file is part of Cachet.
*
* (c) Alt Three Services Limited
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
return [
/*
|--------------------------------------------------------------------------
| Cachet Timezone
|--------------------------------------------------------------------------
|
| The timezone Cachet uses for converting timezones on saving.
|
*/
'timezone' => 'UTC',
];