Navigation Menu

Skip to content

Commit

Permalink
Fix issue with time stamps.
Browse files Browse the repository at this point in the history
  • Loading branch information
JC5 committed Feb 10, 2019
1 parent bf89d99 commit 3c036ae
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions app/Support/Import/Routine/File/ImportableConverter.php
Expand Up @@ -140,8 +140,14 @@ private function convertDateValue(string $date = null): ?string
$result = null;
if (null !== $date) {
try {
$object = Carbon::createFromFormat($this->config['date-format'] ?? 'Ymd', $date);
$result = $object->format('Y-m-d');
// add exclamation mark for better parsing. http://php.net/manual/en/datetime.createfromformat.php
$dateFormat = $this->config['date-format'] ?? 'Ymd';
if ('!' !== $dateFormat{0}) {
$dateFormat = '!' . $dateFormat;
}
$object = Carbon::createFromFormat($dateFormat, $date);
$result = $object->format('Y-m-d H:i:s');
Log::debug(sprintf('createFromFormat: Turning "%s" into "%s" using "%s"', $date, $result, $this->config['date-format'] ?? 'Ymd'));
} catch (InvalidDateException|InvalidArgumentException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
Expand Down Expand Up @@ -213,7 +219,7 @@ private function convertSingle(ImportTransaction $importable): array

return [
'type' => $transactionType,
'date' => $this->convertDateValue($importable->date) ?? Carbon::now()->format('Y-m-d'),
'date' => $this->convertDateValue($importable->date) ?? Carbon::now()->format('Y-m-d H:i:s'),
'tags' => $importable->tags,
'user' => $this->importJob->user_id,
'notes' => $importable->note,
Expand Down

0 comments on commit 3c036ae

Please sign in to comment.