Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.1250
diff -u -p -r1.1250 common.inc
--- includes/common.inc	7 Nov 2010 18:33:52 -0000	1.1250
+++ includes/common.inc	9 Nov 2010 17:47:48 -0000
@@ -1815,25 +1815,25 @@ function format_interval($timestamp, $gr
 }
 
 /**
- * Format a date with the given configured format or a custom format string.
- *
- * Drupal allows administrators to select formatting strings for 'short',
- * 'medium' and 'long' date formats. This function can handle these formats,
- * as well as any custom format.
+ * Formats a date with the given date type or a custom date format string.
  *
  * @param $timestamp
  *   The exact date to format, as a UNIX timestamp.
  * @param $type
- *   The format to use. Can be "short", "medium" or "long" for the preconfigured
- *   date formats. If "custom" is specified, then $format is required as well.
+ *   (optional) The date type to use. Can be 'short', 'medium' or 'long' for the
+ *   date types provided by core, or one of the date types defined by a module
+ *   via hook_date_format_types() or the machine-readable name of a date type
+ *   defined via the admin interface at (admin/config/regional/date-time). If
+ *   'custom' is specified, then $format is required as well. Defaults to
+ *   'medium'.
  * @param $format
- *   A PHP date format string as required by date(). A backslash should be used
- *   before a character to avoid interpreting the character as part of a date
- *   format.
+ *   (optional) A PHP date format string as required by date(). A backslash
+ *   should be used before a character to avoid interpreting the character as
+ *   part of a date format.
  * @param $timezone
- *   Time zone identifier; if omitted, the user's time zone is used.
+ *   (optional) Time zone identifier. Defaults to the user's time zone.
  * @param $langcode
- *   Optional language code to translate to a language other than what is used
+ *   (optional) Language code to translate to a language other than what is used
  *   to display the page.
  * @return
  *   A translated date string in the requested format.
@@ -1862,18 +1862,15 @@ function format_date($timestamp, $type =
   }
 
   switch ($type) {
-    case 'short':
-      $format = variable_get('date_format_short', 'm/d/Y - H:i');
-      break;
-    case 'long':
-      $format = variable_get('date_format_long', 'l, F j, Y - H:i');
-      break;
     case 'custom':
       // No change to format.
       break;
-    case 'medium':
     default:
-      $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
+      $format = variable_get('date_format_' . $type);
+      if (!isset($format)) {
+        // Not able to find the requested format, default to medium.
+        $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
+      }
   }
 
   // Create a DateTime object from the timestamp.
Index: modules/simpletest/tests/common.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/simpletest/tests/common.test,v
retrieving revision 1.130
diff -u -p -r1.130 common.test
--- modules/simpletest/tests/common.test	8 Oct 2010 15:36:12 -0000	1.130
+++ modules/simpletest/tests/common.test	9 Nov 2010 17:47:55 -0000
@@ -2005,6 +2005,32 @@ class FormatDateUnitTest extends DrupalW
   }
 
   /**
+   * Test admin-defined formats in format_date().
+   */
+  function testAdminDefinedFormatDate() {
+    // Create an admin user.
+    $this->admin_user = $this->drupalCreateUser(array('administer site configuration'));
+    $this->drupalLogin($this->admin_user);
+
+    // Add new date format.
+    $admin_date_format = 'j M y';
+    $edit = array('date_format' => $admin_date_format);
+    $this->drupalPost('admin/config/regional/date-time/formats/add', $edit, t('Add format'));
+
+    // Add new date type.
+    $edit = array(
+      'date_type' => 'Example Style',
+      'machine_name' => 'example_style',
+      'date_format' => $admin_date_format,
+    );
+    $this->drupalPost('admin/config/regional/date-time/types/add', $edit, t('Add date type'));
+
+    $timestamp = strtotime('2007-03-10T00:00:00+00:00');
+    $this->assertIdentical(format_date($timestamp, 'example_style', '', 'America/Los_Angeles'), '9 Mar 07', t('Test format_date() using an admin-defined date type.'));
+    $this->assertIdentical(format_date($timestamp, 'undefined_style'), format_date($timestamp, 'medium'), t('Test format_date() defaulting to medium when $type not found.'));
+  }
+
+  /**
    * Tests for the format_date() function.
    */
   function testFormatDate() {
