Skip to content

Commit 80d74c0

Browse files
committed
refactor: replace guessCarbon with guessDate and update related imports and usages
1 parent 1aa31c1 commit 80d74c0

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

app/Livewire/Project/ProjectForm.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
use App\Models\Legacy\LegacyBudgetPlan;
66
use App\Models\Legacy\Project;
7-
use Carbon\Carbon;
87
use Illuminate\Support\Facades\Date;
98
use Livewire\Form;
109

app/Livewire/TransactionImportWire.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function formatDataDb(string|int $value, string $db_col_name): int|string
312312
// if($type === 'decimal') dd([$value, (float) $value,$db_col_name]);
313313
return match ($type) {
314314
'integer' => (int) $value,
315-
'date' => guessCarbon($value, 'Y-m-d'),
315+
'date' => guessDate($value, 'Y-m-d'),
316316
'decimal' => $value, // no casting needed, string is expected
317317
default => $value,
318318
};
@@ -329,7 +329,7 @@ public function formatDataView(string|int $value, string $db_col_name): int|stri
329329
}
330330

331331
return match ($type) {
332-
'date' => guessCarbon($value, 'd.m.Y'),
332+
'date' => guessDate($value, 'd.m.Y'),
333333
'decimal' => number_format((float) $value, 2, ',', '.').'',
334334
'iban' => iban_to_human_format($value),
335335
default => $value

app/Rules/CsvTransactionImport/DateColumnRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ public function __construct(private readonly Collection $column) {}
2020
public function validate(string $attribute, mixed $value, Closure $fail): void
2121
{
2222
try {
23-
$firstDate = guessCarbon($this->column->first());
24-
$lastDate = guessCarbon($this->column->last());
23+
$firstDate = guessDate($this->column->first());
24+
$lastDate = guessDate($this->column->last());
2525
if (! $firstDate->lessThanOrEqualTo($lastDate)) {
2626
$fail(__('konto.csv-verify-date-order-error'));
2727
}

app/Support/helpers.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
/**
88
* Guess the format of the input date because banks do not like standards :(
99
*/
10-
function guessCarbon(string $dateString, ?string $newFormat = null): Carbon|string
10+
function guessDate(string $dateString, ?string $newFormat = null): Date|string
1111
{
1212
$formats = ['d.m.y', 'd.m.Y', 'y-m-d', 'Y-m-d', 'jmy', 'jmY', 'dmy', 'dmY'];
1313
foreach ($formats as $format) {
1414
try {
15-
$ret = \Illuminate\Support\Facades\Date::rawCreateFromFormat($format, $dateString);
15+
$ret = Date::rawCreateFromFormat($format, $dateString);
1616
} catch (InvalidFormatException) {
1717
continue;
1818
}

0 commit comments

Comments
 (0)