2015-07-05 06:18:02 +02:00
|
|
|
<?php
|
2016-05-20 12:27:31 +02:00
|
|
|
/**
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2016-02-05 12:08:25 +01:00
|
|
|
declare(strict_types = 1);
|
2015-07-05 06:18:02 +02:00
|
|
|
namespace FireflyIII\Helpers\Csv\Converter;
|
|
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
2015-08-02 08:53:34 +02:00
|
|
|
use FireflyIII\Exceptions\FireflyException;
|
|
|
|
|
use InvalidArgumentException;
|
|
|
|
|
use Log;
|
2015-07-05 06:18:02 +02:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class Date
|
|
|
|
|
*
|
|
|
|
|
* @package FireflyIII\Helpers\Csv\Converter
|
|
|
|
|
*/
|
|
|
|
|
class Date extends BasicConverter implements ConverterInterface
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
/**
|
2016-01-19 08:48:38 +01:00
|
|
|
* @return Carbon
|
2015-12-28 07:55:09 +01:00
|
|
|
* @throws FireflyException
|
2015-07-05 06:18:02 +02:00
|
|
|
*/
|
2016-04-06 16:37:28 +02:00
|
|
|
public function convert(): Carbon
|
2015-07-05 06:18:02 +02:00
|
|
|
{
|
2016-02-04 07:27:03 +01:00
|
|
|
$format = session('csv-date-format');
|
2015-08-02 08:53:34 +02: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-05 06:18:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
return $date;
|
|
|
|
|
}
|
2015-07-09 21:26:40 +02:00
|
|
|
}
|