Merge branch 'bugfix/remove-date-time-formats-6077'

fixes #6077
This commit is contained in:
Marius Hein 2014-09-04 16:03:15 +02:00
commit d11240d036
6 changed files with 11 additions and 61 deletions

View File

@ -3,7 +3,6 @@
// {{{ICINGA_LICENSE_HEADER}}} // {{{ICINGA_LICENSE_HEADER}}}
use Icinga\Application\Icinga; use Icinga\Application\Icinga;
use Icinga\Application\Config;
use Icinga\Util\DateTimeFactory; use Icinga\Util\DateTimeFactory;
use Icinga\Web\Form\Validator\DateTimeValidator; use Icinga\Web\Form\Validator\DateTimeValidator;
@ -109,10 +108,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
*/ */
public function getDateFormat() public function getDateFormat()
{ {
return $this->request->getUser()->getPreferences()->get( // TODO(mh): Missing localized format (#6077)
'app.dateFormat', return 'd/m/Y';
Config::app()->global !== null ? Config::app()->global->get('dateFormat', 'd/m/Y') : 'd/m/Y'
);
} }
/** /**
@ -122,10 +119,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
*/ */
public function getTimeFormat() public function getTimeFormat()
{ {
return $this->request->getUser()->getPreferences()->get( // TODO(mh): Missing localized format (#6077)
'app.timeFormat', return 'g:i A';
Config::app()->global !== null ? Config::app()->global->get('timeFormat', 'g:i A') : 'g:i A'
);
} }
/** /**

View File

@ -1,7 +1,5 @@
[global] [global]
timezone = "Europe/Berlin" timezone = "Europe/Berlin"
dateFormat = "d/m/Y"
timeFormat = "g:i A"
; Contains the directories that will be searched for available modules. Modules that ; Contains the directories that will be searched for available modules. Modules that
; don't exist in these directories can still be symlinked in the module folder, but ; don't exist in these directories can still be symlinked in the module folder, but

View File

@ -278,9 +278,8 @@ class Monitoring_TimelineController extends Controller
*/ */
private function getTimeFormat() private function getTimeFormat()
{ {
$globalConfig = $this->getGlobalConfiguration(); // TODO(mh): Missing localized format (#6077)
$preferences = $this->getRequest()->getUser()->getPreferences(); return 'g:i A';
return $preferences->get('app.timeFormat', $globalConfig->get('timeFormat', 'g:i A'));
} }
/** /**
@ -290,8 +289,7 @@ class Monitoring_TimelineController extends Controller
*/ */
private function getDateFormat() private function getDateFormat()
{ {
$globalConfig = $this->getGlobalConfiguration(); // TODO(mh): Missing localized format (#6077)
$preferences = $this->getRequest()->getUser()->getPreferences(); return 'd/m/Y';
return $preferences->get('app.dateFormat', $globalConfig->get('dateFormat', 'd/m/Y'));
} }
} }

View File

@ -115,21 +115,8 @@ abstract class CommandForm extends Form
*/ */
public function getValidDateTimeFormats() public function getValidDateTimeFormats()
{ {
$config = $this->getConfiguration(); // TODO(mh): Missing localized format (#6077)
$global = $config->global; return 'd/m/Y g:i A';
if ($global === null) {
$global = new Zend_Config(array());
}
$preferences = $this->getUserPreferences();
return array(
implode(
' ',
array(
$preferences->get('app.dateFormat', $global->get('dateFormat', 'd/m/Y')),
$preferences->get('app.timeFormat', $global->get('timeFormat', 'g:i A'))
)
)
);
} }
/** /**

View File

@ -7,24 +7,14 @@ namespace Tests\Icinga\Views\Helper;
use Mockery; use Mockery;
use Zend_View_Helper_DateFormat; use Zend_View_Helper_DateFormat;
use Icinga\Test\BaseTestCase; use Icinga\Test\BaseTestCase;
use Icinga\Application\Config;
use Icinga\Util\DateTimeFactory; use Icinga\Util\DateTimeFactory;
require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php'; require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php';
class DateFormatTest extends BaseTestCase class DateFormatTest extends BaseTestCase
{ {
public function setUp()
{
parent::setUp();
$this->oldConfigDir = Config::$configDir;
Config::$configDir = dirname(__FILE__) . '/DateFormatTest';
}
public function tearDown() public function tearDown()
{ {
parent::tearDown();
Config::$configDir = $this->oldConfigDir;
DateTimeFactory::setConfig(array('timezone' => date_default_timezone_get())); DateTimeFactory::setConfig(array('timezone' => date_default_timezone_get()));
} }
@ -145,21 +135,6 @@ class DateFormatTest extends BaseTestCase
protected function getRequestMock($dateFormat = null, $timeFormat = null) protected function getRequestMock($dateFormat = null, $timeFormat = null)
{ {
$mock = Mockery::mock('\Zend_Controller_Request_Abstract'); return Mockery::mock('\Zend_Controller_Request_Abstract');
$mock->shouldReceive('getUser->getPreferences->get')
->with(Mockery::type('string'), Mockery::type('string'))
->andReturnUsing(
function ($ident, $default) use ($dateFormat, $timeFormat) {
if ($dateFormat !== null && $ident === 'app.dateFormat') {
return $dateFormat;
} elseif ($timeFormat !== null && $ident === 'app.timeFormat') {
return $timeFormat;
} else {
return $default;
}
}
);
return $mock;
} }
} }

View File

@ -1,3 +0,0 @@
[global]
dateFormat = "d-m-y"
timeFormat = "G:i a"