Bugfix della conversione delle date

This commit is contained in:
Thomas Zilio 2017-09-20 10:26:15 +02:00
parent 4550e55c2d
commit 47fd7c52af
2 changed files with 17 additions and 9 deletions

View File

@ -22,14 +22,22 @@ class DateHandler implements HandlerInterface
$values['min-date'] = date(\Translator::getFormatter()->getStandardFormats()['timestamp']); $values['min-date'] = date(\Translator::getFormatter()->getStandardFormats()['timestamp']);
} }
if ($values['type'] == 'timestamp') { if ($values['type'] == 'timestamp' && \Translator::getFormatter()->isStandardTimestamp($values['value'])) {
$values['value'] = \Translator::timestampToLocale($values['value']); $values['value'] = \Translator::timestampToLocale($values['value']);
} elseif ($values['type'] == 'date') { } elseif ($values['type'] == 'date' && \Translator::getFormatter()->isStandardDate($values['value'])) {
$values['value'] = \Translator::dateToLocale($values['value']); $values['value'] = \Translator::dateToLocale($values['value']);
} elseif ($values['type'] == 'time') { } elseif ($values['type'] == 'time' && \Translator::getFormatter()->isStandardTime($values['value'])) {
$values['value'] = \Translator::timeToLocale($values['value']); $values['value'] = \Translator::timeToLocale($values['value']);
} }
if (!(
($values['type'] == 'timestamp' && \Translator::getFormatter()->isFormattedTimestamp($values['value'])) ||
($values['type'] == 'date' && \Translator::getFormatter()->isFormattedDate($values['value'])) ||
($values['type'] == 'time' && \Translator::getFormatter()->isFormattedTime($values['value']))
)) {
$values['value'] = '';
}
$result = $this->{$values['type']}($values, $extras); $result = $this->{$values['type']}($values, $extras);
$values['type'] = 'text'; $values['type'] = 'text';

View File

@ -21,12 +21,12 @@ class Formatter
/** @var NumberFormatter Oggetto dedicato alla formattazione dei numeri */ /** @var NumberFormatter Oggetto dedicato alla formattazione dei numeri */
protected $numberFormatter; protected $numberFormatter;
/** @var string Pattern per i timestamp */
protected $timestampPattern;
/** @var string Pattern per le date */ /** @var string Pattern per le date */
protected $datePattern; protected $datePattern;
/** @var string Pattern per gli orari */ /** @var string Pattern per gli orari */
protected $timePattern; protected $timePattern;
/** @var string Pattern per i timestamp */
protected $timestampPattern;
public function __construct($locale, $timestamp = null, $date = null, $time = null) public function __construct($locale, $timestamp = null, $date = null, $time = null)
{ {
@ -290,7 +290,7 @@ class Formatter
*/ */
public function getDatePattern($type = null) public function getDatePattern($type = null)
{ {
return $this->timestampPattern; return $this->datePattern;
} }
/** /**
@ -300,7 +300,7 @@ class Formatter
*/ */
public function setDatePattern($pattern) public function setDatePattern($pattern)
{ {
return $this->timestampPattern = $pattern; return $this->datePattern = $pattern;
} }
// Gestione della conversione degli orarii // Gestione della conversione degli orarii
@ -374,7 +374,7 @@ class Formatter
*/ */
public function getTimePattern($type = null) public function getTimePattern($type = null)
{ {
return $this->orarioPattern; return $this->timePattern;
} }
/** /**
@ -384,6 +384,6 @@ class Formatter
*/ */
public function setTimePattern($pattern) public function setTimePattern($pattern)
{ {
return $this->orarioPattern = $pattern; return $this->timePattern = $pattern;
} }
} }