Jenssegers\Date\Date::createFromFormat PHP Method

createFromFormat() public static method

Create a Carbon instance from a specific format.
public static createFromFormat ( string $format, string $time, DateTimeZon\DateTimeZone | string $timezone = null ) : static
$format string
$time string
$timezone DateTimeZon\DateTimeZone | string
return static
    public static function createFromFormat($format, $time, $timezone = null)
    {
        $time = static::translateTimeString($time);
        return parent::createFromFormat($format, $time, $timezone);
    }

Usage Example

 /**
  * Handle the report incident command.
  *
  * @param \CachetHQ\Cachet\Commands\Incident\ReportIncidentCommand $command
  *
  * @return \CachetHQ\Cachet\Models\Incident
  */
 public function handle(ReportIncidentCommand $command)
 {
     $data = ['name' => $command->name, 'status' => $command->status, 'message' => $command->message, 'visible' => $command->visible];
     // Link with the component.
     if ($command->component_id) {
         $data['component_id'] = $command->component_id;
     }
     // 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'));
         $data['created_at'] = $incidentDate;
         $data['updated_at'] = $incidentDate;
     }
     // Create the incident
     $incident = Incident::create($data);
     // Update the component.
     if ($command->component_id) {
         Component::find($command->component_id)->update(['status' => $command->component_status]);
     }
     // Notify subscribers.
     if ($command->notify) {
         event(new IncidentWasReportedEvent($incident));
     }
     return $incident;
 }
All Usage Examples Of Jenssegers\Date\Date::createFromFormat