mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-01-08 07:03:23 -06:00
40 lines
937 B
PHP
40 lines
937 B
PHP
<?php
|
|
|
|
namespace FireflyIII\Helpers\Csv\Converter;
|
|
|
|
use Carbon\Carbon;
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
use InvalidArgumentException;
|
|
use Log;
|
|
use Session;
|
|
|
|
/**
|
|
* Class Date
|
|
*
|
|
* @package FireflyIII\Helpers\Csv\Converter
|
|
*/
|
|
class Date extends BasicConverter implements ConverterInterface
|
|
{
|
|
|
|
/**
|
|
* @return static
|
|
* @throws FireflyException
|
|
*/
|
|
public function convert()
|
|
{
|
|
$format = Session::get('csv-date-format');
|
|
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);
|
|
}
|
|
|
|
|
|
return $date;
|
|
}
|
|
}
|