Skip to content

Commit

Permalink
Catching weird Carbon errors
Browse files Browse the repository at this point in the history
  • Loading branch information
Josef Citrine committed Jan 25, 2017
1 parent 7d9eaf9 commit 3217062
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions app/Commands/ParseTrackTagsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public function execute()
$this->track->track_number = null;
} else {
$this->track->track_number = filter_var($this->input['track_number'] ?? $parsedTags['track_number'], FILTER_SANITIZE_NUMBER_INT);
if ($this->track->track_number == null) {
if ($this->track->track_number === null) {
$this->track->track_number = 1;
}
}
Expand Down Expand Up @@ -463,18 +463,30 @@ protected function parseDateString(string $dateString)
switch (Str::length($dateString)) {
// YYYY
case 4:
return Carbon::createFromFormat('Y', $dateString)
->month(1)
->day(1);
try {
return Carbon::createFromFormat('Y', $dateString)
->month(1)
->day(1);
} catch (\InvalidArgumentException $e) {
return null;
}

// YYYY-MM
case 7:
return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString))
->day(1);
try {
return Carbon::createFromFormat('Y m', str_replace("-", " ", $dateString))
->day(1);
} catch (\InvalidArgumentException $e) {
return null;
}

// YYYY-MM-DD
case 10:
return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString));
try {
return Carbon::createFromFormat('Y m d', str_replace("-", " ", $dateString));
} catch (\InvalidArgumentException $e) {
return null;
}
break;

default:
Expand Down

0 comments on commit 3217062

Please sign in to comment.