2015-07-04 23:18:02 -05:00
|
|
|
<?php
|
2016-02-05 05:08:25 -06:00
|
|
|
declare(strict_types = 1);
|
2015-07-04 23:18:02 -05:00
|
|
|
namespace FireflyIII\Helpers\Csv\Converter;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2015-08-02 01:53:34 -05:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
|
|
use InvalidArgumentException;
|
|
|
|
use Log;
|
2015-07-04 23:18:02 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Class Date
|
|
|
|
*
|
|
|
|
* @package FireflyIII\Helpers\Csv\Converter
|
|
|
|
*/
|
|
|
|
class Date extends BasicConverter implements ConverterInterface
|
|
|
|
{
|
|
|
|
|
|
|
|
/**
|
2016-01-19 01:48:38 -06:00
|
|
|
* @return Carbon
|
2015-12-28 00:55:09 -06:00
|
|
|
* @throws FireflyException
|
2015-07-04 23:18:02 -05:00
|
|
|
*/
|
|
|
|
public function convert()
|
|
|
|
{
|
2016-02-04 00:27:03 -06:00
|
|
|
$format = session('csv-date-format');
|
2015-08-02 01:53:34 -05:00
|
|
|
try {
|
|
|
|
$date = Carbon::createFromFormat($format, $this->value);
|
|
|
|
} catch (InvalidArgumentException $e) {
|
|
|
|
Log::error('Date conversion error: ' . $e->getMessage() . '. Value was "' . $this->value . '", format was "' . $format . '".');
|
|
|
|
|
|
|
|
$message = trans('firefly.csv_date_parse_error', ['format' => $format, 'value' => $this->value]);
|
|
|
|
|
|
|
|
throw new FireflyException($message);
|
|
|
|
}
|
2015-07-04 23:18:02 -05:00
|
|
|
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
}
|
2015-07-09 14:26:40 -05:00
|
|
|
}
|