diff --git a/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php b/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php index e0f6e8c3..6ac350d3 100644 --- a/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/ReportIncidentCommandHandler.php @@ -12,14 +12,32 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident; use CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand; +use CachetHQ\Cachet\Dates\DateFactory; use CachetHQ\Cachet\Events\Incident\IncidentWasReportedEvent; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Incident; -use Illuminate\Support\Facades\Config; -use Jenssegers\Date\Date; class ReportIncidentCommandHandler { + /** + * The date factory instance. + * + * @var \CachetHQ\Cachet\Dates\DateFactory + */ + protected $dates; + + /** + * Create a new report incident command handler instance. + * + * @param \CachetHQ\Cachet\Dates\DateFactory $dates + * + * @return void + */ + public function __construct(DateFactory $dates) + { + $this->dates = $dates; + } + /** * Handle the report incident command. * @@ -43,7 +61,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, config('cachet.timezone'))->setTimezone(Config::get('app.timezone')); + $incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date); $data['created_at'] = $incidentDate; $data['updated_at'] = $incidentDate; diff --git a/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php b/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php index 2239cf8c..d1f0a793 100644 --- a/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php +++ b/app/Handlers/Commands/Incident/ReportMaintenanceCommandHandler.php @@ -12,13 +12,31 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident; use CachetHQ\Cachet\Commands\Incident\ReportMaintenanceCommand; +use CachetHQ\Cachet\Dates\DateFactory; use CachetHQ\Cachet\Events\Incident\MaintenanceWasScheduledEvent; use CachetHQ\Cachet\Models\Incident; -use Illuminate\Support\Facades\Config; -use Jenssegers\Date\Date; class ReportMaintenanceCommandHandler { + /** + * The date factory instance. + * + * @var \CachetHQ\Cachet\Dates\DateFactory + */ + protected $dates; + + /** + * Create a new report maintanance command handler instance. + * + * @param \CachetHQ\Cachet\Dates\DateFactory $dates + * + * @return void + */ + public function __construct(DateFactory $dates) + { + $this->dates = $dates; + } + /** * Handle the report maintenance command. * @@ -28,8 +46,7 @@ class ReportMaintenanceCommandHandler */ public function handle(ReportMaintenanceCommand $command) { - $scheduledAt = Date::createFromFormat('d/m/Y H:i', $command->timestamp, config('cachet.timezone')) - ->setTimezone(Config::get('app.timezone')); + $scheduledAt = $this->dates->createNormalized('d/m/Y H:i', $command->timestamp); $maintenanceEvent = Incident::create([ 'name' => $command->name, diff --git a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php index dc3af1ca..dbc8ecfe 100644 --- a/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php +++ b/app/Handlers/Commands/Incident/UpdateIncidentCommandHandler.php @@ -12,14 +12,32 @@ namespace CachetHQ\Cachet\Handlers\Commands\Incident; use CachetHQ\Cachet\Commands\Incident\UpdateIncidentCommand; +use CachetHQ\Cachet\Dates\DateFactory; use CachetHQ\Cachet\Events\Incident\IncidentWasUpdatedEvent; use CachetHQ\Cachet\Models\Component; use CachetHQ\Cachet\Models\Incident; -use Illuminate\Support\Facades\Config; -use Jenssegers\Date\Date; class UpdateIncidentCommandHandler { + /** + * The date factory instance. + * + * @var \CachetHQ\Cachet\Dates\DateFactory + */ + protected $dates; + + /** + * Create a new update incident command handler instance. + * + * @param \CachetHQ\Cachet\Dates\DateFactory $dates + * + * @return void + */ + public function __construct(DateFactory $dates) + { + $this->dates = $dates; + } + /** * Handle the update incident command. * @@ -34,7 +52,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, config('cachet.timezone'))->setTimezone(Config::get('app.timezone')); + $incidentDate = $this->dates->createNormalized('d/m/Y H:i', $command->incident_date); $incident->update([ 'created_at' => $incidentDate,