diff --git a/app/Certificate.php b/app/Certificate.php index 24b9f1ca..a15b5707 100644 --- a/app/Certificate.php +++ b/app/Certificate.php @@ -45,7 +45,10 @@ public function getStartValidityAttribute($value) public function setStartValidityAttribute($value) { - $this->attributes['start_validity'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; + $this->attributes['start_validity'] = + $this->parseDate( + $value, + config('panel.date_format')); } public function getEndValidityAttribute($value) @@ -55,7 +58,10 @@ public function getEndValidityAttribute($value) public function setEndValidityAttribute($value) { - $this->attributes['end_validity'] = $value ? Carbon::createFromFormat(config('panel.date_format'), $value)->format('Y-m-d') : null; + $this->attributes['end_validity'] = + $this->parseDate( + $value, + config('panel.date_format')); } public function getLastNotificationAttribute($value) @@ -77,4 +83,16 @@ protected function serializeDate(DateTimeInterface $date) { return $date->format('Y-m-d H:i:s'); } + + private function parseDate($value, $format = null) + { + $format = $format ? $format : config('panel.date_format'); + + try { + return $value ? Carbon::createFromFormat($format, $value)->format('Y-m-d') : null; + } catch (\Exception $e) { + Log::error('Invalid date format: ' . $value . ' with format ' . $format); + return null; + } + } } diff --git a/app/MApplication.php b/app/MApplication.php index 02a249e9..91a4a845 100644 --- a/app/MApplication.php +++ b/app/MApplication.php @@ -78,7 +78,10 @@ public function getUpdateDateAttribute($value) public function setUpdateDateAttribute($value) { - $this->attributes['update_date'] = $this->parseDate($value); + $this->attributes['update_date'] = + $this->parseDate( + $value, + config('panel.date_format') . ' ' . config('panel.time_format')); } public function getInstallDateAttribute($value) @@ -88,7 +91,10 @@ public function getInstallDateAttribute($value) public function setInstallDateAttribute($value) { - $this->attributes['install_date'] = $this->parseDate($value); + $this->attributes['install_date'] = + $this->parseDate( + $value, + config('panel.date_format') . ' ' . config('panel.time_format')); } public function getNextUpdateAttribute($value)