Skip to content
Permalink
Browse files

Merge pull request #389 from mirsch/fix/different-date-formats

detect date format in field notes
  • Loading branch information...
teiling88 committed Sep 5, 2016
2 parents 72cfd2c + bb6e31d commit e97e00f626d65826d5fe75f769ee925b4665e280
@@ -62,16 +62,7 @@ public function importFromFile($fileName, $userId, DateTime $ignoreBeforeDate =
);
}
$date = DateTime::createFromFormat(
self::FIELD_NOTE_DATETIME_FORMAT,
$data[1],
new DateTimeZone('UTC')
);
if (!$date) {
throw new WrongDateFormatException(
$this->translator->trans('field_notes.error.wrong_date_format')
);
}
$date = $this->getDate($data[1]);
if ($ignoreBeforeDate !== null && $date < $ignoreBeforeDate) {
continue;
@@ -148,4 +139,34 @@ protected function getMaxDateFromEntityByUserId($entityName, $userId)
return $max;
}
/**
* @param string $dateString
*
* @throws \AppBundle\Exception\WrongDateFormatException
* @return \DateTime
*/
protected function getDate($dateString)
{
$format = null;
if (preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}Z/', $dateString)) {
$format = self::FIELD_NOTE_DATETIME_FORMAT_SHORT;
} elseif (preg_match('/[0-9]{4}-[0-9]{2}-[0-9]{2}T[0-9]{2}:[0-9]{2}:[0-9]{2}Z/', $dateString)) {
$format = self::FIELD_NOTE_DATETIME_FORMAT;
}
if ($format === null) {
throw new WrongDateFormatException(
$this->translator->trans('field_notes.error.wrong_date_format')
);
}
$date = DateTime::createFromFormat(
$format,
$dateString,
new DateTimeZone('UTC')
);
return $date;
}
}
@@ -7,6 +7,7 @@
interface FieldNoteServiceInterface extends ErrorInterface
{
const FIELD_NOTE_DATETIME_FORMAT = 'Y-m-d\TH:i:s\Z';
const FIELD_NOTE_DATETIME_FORMAT_SHORT = 'Y-m-d\TH:i\Z';
const LOG_TYPE = [
'Found it' => FieldNote::LOG_TYPE_FOUND,
"Didn't find it" => FieldNote::LOG_TYPE_NOT_FOUND,

0 comments on commit e97e00f

Please sign in to comment.
You can’t perform that action at this time.