From 6fcf5ec88a19d831ea68b5fe69c0e57741d4d792 Mon Sep 17 00:00:00 2001
From: Marius Hein <marius.hein@netways.de>
Date: Thu, 4 Sep 2014 15:55:28 +0200
Subject: [PATCH 1/2] DateTime: Remove global and user formattings

refs #6077
---
 application/views/helpers/DateFormat.php        | 13 ++++---------
 config/config.ini.in                            |  2 --
 .../controllers/TimelineController.php          | 10 ++++------
 .../application/forms/Command/CommandForm.php   | 17 ++---------------
 4 files changed, 10 insertions(+), 32 deletions(-)

diff --git a/application/views/helpers/DateFormat.php b/application/views/helpers/DateFormat.php
index a03316f25..28cb81f32 100644
--- a/application/views/helpers/DateFormat.php
+++ b/application/views/helpers/DateFormat.php
@@ -3,7 +3,6 @@
 // {{{ICINGA_LICENSE_HEADER}}}
 
 use Icinga\Application\Icinga;
-use Icinga\Application\Config;
 use Icinga\Util\DateTimeFactory;
 use Icinga\Web\Form\Validator\DateTimeValidator;
 
@@ -109,10 +108,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
      */
     public function getDateFormat()
     {
-        return $this->request->getUser()->getPreferences()->get(
-            'app.dateFormat',
-            Config::app()->global !== null ? Config::app()->global->get('dateFormat', 'd/m/Y') : 'd/m/Y'
-        );
+        // TODO(mh): Missing localized format (#6077)
+        return 'd/m/Y';
     }
 
     /**
@@ -122,10 +119,8 @@ class Zend_View_Helper_DateFormat extends Zend_View_Helper_Abstract
      */
     public function getTimeFormat()
     {
-        return $this->request->getUser()->getPreferences()->get(
-            'app.timeFormat',
-            Config::app()->global !== null ? Config::app()->global->get('timeFormat', 'g:i A') : 'g:i A'
-        );
+        // TODO(mh): Missing localized format (#6077)
+        return 'g:i A';
     }
 
     /**
diff --git a/config/config.ini.in b/config/config.ini.in
index 72987094f..560acf527 100644
--- a/config/config.ini.in
+++ b/config/config.ini.in
@@ -1,7 +1,5 @@
 [global]
 timezone            = "Europe/Berlin"
-dateFormat          = "d/m/Y"
-timeFormat          = "g:i A"
 
 ; 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
diff --git a/modules/monitoring/application/controllers/TimelineController.php b/modules/monitoring/application/controllers/TimelineController.php
index 3fa621f3e..2da29a0b9 100644
--- a/modules/monitoring/application/controllers/TimelineController.php
+++ b/modules/monitoring/application/controllers/TimelineController.php
@@ -278,9 +278,8 @@ class Monitoring_TimelineController extends Controller
      */
     private function getTimeFormat()
     {
-        $globalConfig = $this->getGlobalConfiguration();
-        $preferences = $this->getRequest()->getUser()->getPreferences();
-        return $preferences->get('app.timeFormat', $globalConfig->get('timeFormat', 'g:i A'));
+        // TODO(mh): Missing localized format (#6077)
+        return 'g:i A';
     }
 
     /**
@@ -290,8 +289,7 @@ class Monitoring_TimelineController extends Controller
      */
     private function getDateFormat()
     {
-        $globalConfig = $this->getGlobalConfiguration();
-        $preferences = $this->getRequest()->getUser()->getPreferences();
-        return $preferences->get('app.dateFormat', $globalConfig->get('dateFormat', 'd/m/Y'));
+        // TODO(mh): Missing localized format (#6077)
+        return 'd/m/Y';
     }
 }
diff --git a/modules/monitoring/application/forms/Command/CommandForm.php b/modules/monitoring/application/forms/Command/CommandForm.php
index df1bed008..1e458a44e 100644
--- a/modules/monitoring/application/forms/Command/CommandForm.php
+++ b/modules/monitoring/application/forms/Command/CommandForm.php
@@ -115,21 +115,8 @@ abstract class CommandForm extends Form
      */
     public function getValidDateTimeFormats()
     {
-        $config = $this->getConfiguration();
-        $global = $config->global;
-        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'))
-                )
-            )
-        );
+        // TODO(mh): Missing localized format (#6077)
+        return 'd/m/Y g:i A';
     }
 
     /**

From 0935a8e34027052ffa2b0d9315f78b7e07d38bf6 Mon Sep 17 00:00:00 2001
From: Marius Hein <marius.hein@netways.de>
Date: Thu, 4 Sep 2014 16:01:24 +0200
Subject: [PATCH 2/2] DateFormatTest: Remove dependencies to global/user config

refs #6077
---
 .../views/helpers/DateFormatTest.php          | 27 +------------------
 .../views/helpers/DateFormatTest/config.ini   |  3 ---
 2 files changed, 1 insertion(+), 29 deletions(-)
 delete mode 100644 test/php/application/views/helpers/DateFormatTest/config.ini

diff --git a/test/php/application/views/helpers/DateFormatTest.php b/test/php/application/views/helpers/DateFormatTest.php
index 8de8442f6..4f3cfc184 100644
--- a/test/php/application/views/helpers/DateFormatTest.php
+++ b/test/php/application/views/helpers/DateFormatTest.php
@@ -7,24 +7,14 @@ namespace Tests\Icinga\Views\Helper;
 use Mockery;
 use Zend_View_Helper_DateFormat;
 use Icinga\Test\BaseTestCase;
-use Icinga\Application\Config;
 use Icinga\Util\DateTimeFactory;
 
 require_once BaseTestCase::$appDir . '/views/helpers/DateFormat.php';
 
 class DateFormatTest extends BaseTestCase
 {
-    public function setUp()
-    {
-        parent::setUp();
-        $this->oldConfigDir = Config::$configDir;
-        Config::$configDir = dirname(__FILE__) . '/DateFormatTest';
-    }
-
     public function tearDown()
     {
-        parent::tearDown();
-        Config::$configDir = $this->oldConfigDir;
         DateTimeFactory::setConfig(array('timezone' => date_default_timezone_get()));
     }
 
@@ -145,21 +135,6 @@ class DateFormatTest extends BaseTestCase
 
     protected function getRequestMock($dateFormat = null, $timeFormat = null)
     {
-        $mock = 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;
+        return Mockery::mock('\Zend_Controller_Request_Abstract');
     }
 }
diff --git a/test/php/application/views/helpers/DateFormatTest/config.ini b/test/php/application/views/helpers/DateFormatTest/config.ini
deleted file mode 100644
index f095d27ca..000000000
--- a/test/php/application/views/helpers/DateFormatTest/config.ini
+++ /dev/null
@@ -1,3 +0,0 @@
-[global]
-dateFormat = "d-m-y"
-timeFormat = "G:i a"
\ No newline at end of file