added support for Ante meridiem and Post meridiem format (#615)
This commit is contained in:
@@ -960,6 +960,11 @@ class KimaiImporterCommand extends Command
|
||||
continue;
|
||||
}
|
||||
|
||||
if (empty($oldRecord['end']) || $oldRecord['end'] === 0) {
|
||||
$io->error('Cannot import running timesheet record, skipping: ' . $oldRecord['timeEntryID']);
|
||||
continue;
|
||||
}
|
||||
|
||||
$duration = $oldRecord['end'] - $oldRecord['start'];
|
||||
|
||||
// ----------------------- unknown user, damned missing data integrity in Kimai v1 -----------------------
|
||||
|
||||
@@ -195,6 +195,7 @@ class Configuration implements ConfigurationInterface
|
||||
$node = $builder->root('languages');
|
||||
|
||||
$node
|
||||
->useAttributeAsKey('name', false) // see https://github.com/symfony/symfony/issues/18988
|
||||
->arrayPrototype()
|
||||
->children()
|
||||
->scalarNode('date_time_type')->defaultValue('yyyy-MM-dd HH:mm')->end() // for DateTimeType
|
||||
@@ -204,6 +205,8 @@ class Configuration implements ConfigurationInterface
|
||||
->scalarNode('date')->defaultValue('Y-m-d')->end() // for display via twig
|
||||
->scalarNode('date_time')->defaultValue('m-d H:i')->end() // for display via twig
|
||||
->scalarNode('duration')->defaultValue('%%h:%%m h')->end() // for display via twig
|
||||
->scalarNode('time')->defaultValue('H:i')->end() // for display via twig
|
||||
->booleanNode('24_hours')->defaultTrue()->end() // for DateTimeType JS component
|
||||
->end()
|
||||
->end()
|
||||
;
|
||||
|
||||
@@ -19,9 +19,25 @@ use Twig\TwigFilter;
|
||||
class DateExtensions extends \Twig_Extension
|
||||
{
|
||||
/**
|
||||
* @var LocaleSettings
|
||||
* @var LocaleSettings|null
|
||||
*/
|
||||
protected $localeSettings;
|
||||
protected $localeSettings = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dateFormat = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $dateTimeFormat = null;
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $timeFormat = null;
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected $isTwentyFourHour = null;
|
||||
|
||||
/**
|
||||
* @param LocaleSettings $localeSettings
|
||||
@@ -42,6 +58,7 @@ class DateExtensions extends \Twig_Extension
|
||||
new TwigFilter('date_time', [$this, 'dateTime']),
|
||||
new TwigFilter('date_format', [$this, 'dateFormat']),
|
||||
new TwigFilter('time', [$this, 'time']),
|
||||
new TwigFilter('hour24', [$this, 'hour24']),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -51,9 +68,11 @@ class DateExtensions extends \Twig_Extension
|
||||
*/
|
||||
public function dateShort(DateTime $date)
|
||||
{
|
||||
$format = $this->localeSettings->getDateFormat();
|
||||
if (null === $this->dateFormat) {
|
||||
$this->dateFormat = $this->localeSettings->getDateFormat();
|
||||
}
|
||||
|
||||
return date_format($date, $format);
|
||||
return date_format($date, $this->dateFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,9 +81,11 @@ class DateExtensions extends \Twig_Extension
|
||||
*/
|
||||
public function dateTime(DateTime $date)
|
||||
{
|
||||
$format = $this->localeSettings->getDateTimeFormat();
|
||||
if (null === $this->dateTimeFormat) {
|
||||
$this->dateTimeFormat = $this->localeSettings->getDateTimeFormat();
|
||||
}
|
||||
|
||||
return date_format($date, $format);
|
||||
return date_format($date, $this->dateTimeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -83,7 +104,11 @@ class DateExtensions extends \Twig_Extension
|
||||
*/
|
||||
public function time(DateTime $date)
|
||||
{
|
||||
return date_format($date, 'H:i');
|
||||
if (null === $this->timeFormat) {
|
||||
$this->timeFormat = $this->localeSettings->getTimeFormat();
|
||||
}
|
||||
|
||||
return date_format($date, $this->timeFormat);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -94,4 +119,22 @@ class DateExtensions extends \Twig_Extension
|
||||
{
|
||||
return 'month.' . $date->format('n');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $twentyFour
|
||||
* @param mixed $twelveHour
|
||||
* @return mixed
|
||||
*/
|
||||
public function hour24($twentyFour, $twelveHour)
|
||||
{
|
||||
if (null === $this->isTwentyFourHour) {
|
||||
$this->isTwentyFourHour = $this->localeSettings->isTwentyFourHours();
|
||||
}
|
||||
|
||||
if (true === $this->isTwentyFourHour) {
|
||||
return $twentyFour;
|
||||
}
|
||||
|
||||
return $twelveHour;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,6 +111,17 @@ class LocaleSettings
|
||||
return $this->getConfigByLocaleAndKey('date', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale specific time format, which should be used in combination with the twig filter "|time".
|
||||
*
|
||||
* @param null|string $locale
|
||||
* @return string
|
||||
*/
|
||||
public function getTimeFormat(?string $locale = null): string
|
||||
{
|
||||
return $this->getConfigByLocaleAndKey('time', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the locale specific datetime format, which should be used in combination with the twig filter "|date".
|
||||
*
|
||||
@@ -133,6 +144,17 @@ class LocaleSettings
|
||||
return $this->getConfigByLocaleAndKey('duration', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether this locale uses the 24 hour format.
|
||||
*
|
||||
* @param null|string $locale
|
||||
* @return bool
|
||||
*/
|
||||
public function isTwentyFourHours(?string $locale = null): bool
|
||||
{
|
||||
return $this->getConfigByLocaleAndKey('24_hours', $locale);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @param null|string $locale
|
||||
|
||||
Reference in New Issue
Block a user