Index: trunk/lib/App.inc.php
===================================================================
--- trunk/lib/App.inc.php	(revision 739)
+++ trunk/lib/App.inc.php	(revision 740)
@@ -1879,6 +1879,11 @@
         }
 
-        // Create a DateTime object and conver the timezone from server to user.
-        $dt = $this->convertTZ($datetime, $this->getParam('php_timezone'), $this->getParam('user_timezone'));
+        try {
+            // Create a DateTime object and conver the timezone from server to user.
+            $dt = $this->convertTZ($datetime, $this->getParam('php_timezone'), $this->getParam('user_timezone'));
+        } catch (Exception $e) {
+            $this->logMsg(sprintf('DateTime failed to parse string in %s: %s', __METHOD__, $datetime), LOG_NOTICE, __FILE__, __LINE__);
+            return '';
+        }
 
         // By default, we try to use a localized date format. Set lc_date_format to null to use regular date_format instead.
@@ -1906,5 +1911,13 @@
     function dateToServerTZ($datetime, $format='Y-m-d H:i:s')
     {
-        return $this->convertTZ($datetime, $this->getParam('user_timezone'), $this->getParam('php_timezone'))->format($format);
+        try {
+            // Create a DateTime object and conver the timezone from server to user.
+            $dt = $this->convertTZ($datetime, $this->getParam('user_timezone'), $this->getParam('php_timezone'));
+        } catch (Exception $e) {
+            $this->logMsg(sprintf('DateTime failed to parse string in %s: %s', __METHOD__, $datetime), LOG_NOTICE, __FILE__, __LINE__);
+            return '';
+        }
+
+        return $dt->format($format);
     }
 
Index: trunk/lib/Prefs.inc.php
===================================================================
--- trunk/lib/Prefs.inc.php	(revision 739)
+++ trunk/lib/Prefs.inc.php	(revision 740)
@@ -332,5 +332,5 @@
             if (!(isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults']))
             || $_SESSION['_prefs'][$this->_ns]['defaults'][$key] != $val
-            || (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']))) {
+            || $this->exists($key)) {
                 $_SESSION['_prefs'][$this->_ns]['saved'][$key] = $val;
                 $app->logMsg(sprintf('Setting session/database preference %s => %s', $key, getDump($val, true)), LOG_DEBUG, __FILE__, __LINE__);
@@ -355,9 +355,8 @@
      * a default value is returned, or if not that, null.
      *
-     * @param string $key       The name of the preference to retrieve.
-     *
+     * @param string $key       The name of the preference to retrieve (or null to retrieve all keys).
      * @return string           The value of the preference.
      */
-    public function get($key)
+    public function get($key=null)
     {
         $app =& App::getInstance();
@@ -368,16 +367,23 @@
         case 'session':
         case 'database':
-            if (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved'])) {
+            if (is_null($key) && isset($_SESSION['_prefs'][$this->_ns]['saved'])) {
+                return $_SESSION['_prefs'][$this->_ns]['saved'];
+            }
+            if ($this->exists($key)) {
                 $app->logMsg(sprintf('Found %s in saved', $key), LOG_DEBUG, __FILE__, __LINE__);
                 return $_SESSION['_prefs'][$this->_ns]['saved'][$key];
-            } else if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
+            }
+            if (isset($_SESSION['_prefs'][$this->_ns]['defaults']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['defaults'])) {
                 $app->logMsg(sprintf('Found %s in defaults', $key), LOG_DEBUG, __FILE__, __LINE__);
                 return $_SESSION['_prefs'][$this->_ns]['defaults'][$key];
-            } else {
-                $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
-            }
+            }
+            $app->logMsg(sprintf('Key not found in prefs cache: %s', $key), LOG_DEBUG, __FILE__, __LINE__);
             return null;
 
         case 'cookie':
+            if (is_null($key)) {
+                $app->logMsg(sprintf('Unable to get(null) when using cookie storagetype.', null), LOG_WARNING, __FILE__, __LINE__);
+                return null;
+            }
             $name = $this->_getCookieName($key);
             if ($this->exists($key) && '' != $_COOKIE[$name]) {
@@ -385,7 +391,6 @@
                 $app->logMsg(sprintf('Found %s in cookie: %s', $key, getDump($val)), LOG_DEBUG, __FILE__, __LINE__);
                 return $val;
-            } else {
-                $app->logMsg(sprintf('Did not find %s in cookie', $key), LOG_DEBUG, __FILE__, __LINE__);
-            }
+            }
+            $app->logMsg(sprintf('Did not find %s in cookie', $key), LOG_DEBUG, __FILE__, __LINE__);
             return null;
         }
@@ -405,4 +410,5 @@
         case 'session':
         case 'database':
+            // isset() does not return TRUE for array keys that correspond to a NULL value, while array_key_exists() does.
             return (isset($_SESSION['_prefs'][$this->_ns]['saved']) && array_key_exists($key, $_SESSION['_prefs'][$this->_ns]['saved']));
 
