firefly-iii/app/Import/Converter/Date.php

52 lines
1.3 KiB
PHP
Raw Normal View History

2016-07-16 00:58:25 -05:00
<?php
/**
* Date.php
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Import\Converter;
use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use InvalidArgumentException;
use Log;
/**
* Class Date
*
* @package FireflyIII\Import\Converter
*/
class Date extends BasicConverter implements ConverterInterface
{
/**
* @param $value
*
* @return Carbon
* @throws FireflyException
*/
public function convert($value): Carbon
{
2016-08-12 02:27:09 -05:00
Log::debug('Going to convert date', ['value' => $value]);
2016-07-16 00:58:25 -05:00
Log::debug('Format: ', ['format' => $this->config['date-format']]);
try {
$date = Carbon::createFromFormat($this->config['date-format'], $value);
} catch (InvalidArgumentException $e) {
Log::info($e->getMessage());
Log::info('Cannot convert this string using the given format.', ['value' => $value, 'format' => $this->config['date-format']]);
2016-08-11 11:44:11 -05:00
$this->setCertainty(0);
2016-08-26 01:21:31 -05:00
2016-08-11 11:44:11 -05:00
return new Carbon;
2016-07-16 00:58:25 -05:00
}
Log::debug('Converted date', ['converted' => $date->toAtomString()]);
$this->setCertainty(100);
2016-08-26 01:21:31 -05:00
2016-07-16 00:58:25 -05:00
return $date;
}
2016-08-12 08:10:03 -05:00
}