Index: modules/system/admin.css
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/admin.css,v
retrieving revision 1.12
diff -u -p -r1.12 admin.css
--- modules/system/admin.css	23 Nov 2006 11:05:46 -0000	1.12
+++ modules/system/admin.css	2 Mar 2007 22:19:17 -0000
@@ -96,4 +96,22 @@ table.system-status-report tr.ok th {
 }
 .theme-settings-bottom {
   clear: both;
-}
\ No newline at end of file
+}
+
+/*
+** Date and time settings page
+*/
+div.date-container {
+  overflow: auto;
+}
+
+div.date-container > div {
+  float: left;
+}
+
+div.date-container #short-custom-div,
+div.date-container #medium-custom-div,
+div.date-container #long-custom-div {
+  margin-left: 15px;
+  width: 50%;
+}
Index: modules/system/system.js
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.js,v
retrieving revision 1.1
diff -u -p -r1.1 system.js
--- modules/system/system.js	13 Feb 2007 07:41:51 -0000	1.1
+++ modules/system/system.js	2 Mar 2007 22:19:17 -0000
@@ -22,3 +22,61 @@ Drupal.cleanURLsSettingsCheck = function
     }
   }});
 }
+
+/**
+ * Show/hide custom format sections on the date-time settings page.
+ */
+Drupal.dateTimeAutoAttach = function() {
+  $("#edit-date-format-short").change(function() {
+    if ($(this).val() == "custom") {
+      $("#short-custom-div").show();
+    }
+    else {
+      $("#short-custom-div").hide();
+    }
+  });
+
+  $("#edit-date-format-medium").change(function() {
+    if ($(this).val() == "custom") {
+      $("#medium-custom-div").show();
+    }
+    else {
+      $("#medium-custom-div").hide();
+    }
+  });
+
+  $("#edit-date-format-long").change(function() {
+    if ($(this).val() == "custom") {
+      $("#long-custom-div").show();
+    }
+    else {
+      $("#long-custom-div").hide();
+    }
+  });
+
+  // Hide the labels to simplify the UI.
+  $("#short-custom-div .form-item label").html("&nbsp;");
+  $("#medium-custom-div .form-item label").html("&nbsp;");
+  $("#long-custom-div .form-item label").html("&nbsp;");
+
+  // Save handler into a variable so that it can be re-used for each input.
+  var datetimeHandler = function() {
+    var input = $(this);
+    // Double encode format string so that backslashes are sent properly.
+    var url = Drupal.settings.datetime.lookup +"/"+ encodeURIComponent(encodeURIComponent(input.val()));
+    $.ajax({type: "GET", url: url, success: function(data) {
+      data = Drupal.parseJson(data);
+      $(".description span", input.parent()).html(data.response);
+    }});
+  };
+
+  // Attach keypress handlers to each custom format input.
+  $("#edit-date-format-short-custom").keyup(datetimeHandler);
+  $("#edit-date-format-medium-custom").keyup(datetimeHandler);
+  $("#edit-date-format-long-custom").keyup(datetimeHandler);
+
+  // Trigger the event handler to show the form input if necessary.
+  $("#edit-date-format-short").trigger("change");
+  $("#edit-date-format-medium").trigger("change");
+  $("#edit-date-format-long").trigger("change");
+}
Index: modules/system/system.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/system/system.module,v
retrieving revision 1.452
diff -u -p -r1.452 system.module
--- modules/system/system.module	27 Feb 2007 12:29:22 -0000	1.452
+++ modules/system/system.module	2 Mar 2007 22:19:20 -0000
@@ -243,6 +243,11 @@ function system_menu() {
     'page callback' => 'drupal_get_form',
     'page arguments' => array('system_date_time_settings'),
   );
+  $items['admin/settings/date-time/lookup'] = array(
+    'title' => t('Date and time lookup'),
+    'type' => MENU_CALLBACK,
+    'page callback' => 'system_date_time_lookup',
+  );
   $items['admin/settings/site-maintenance'] = array(
     'title' => t('Site maintenance'),
     'description' => t('Take the site off-line for maintenance or bring it back online.'),
@@ -774,6 +779,15 @@ function system_rss_feeds_settings() {
 }
 
 function system_date_time_settings() {
+  drupal_add_js(drupal_get_path('module', 'system') .'/system.js', 'module');
+  drupal_add_js(array('datetime' => array('lookup' => url('admin/settings/date-time/lookup'))), 'setting');
+  drupal_add_js('
+// Global Killswitch
+if (Drupal.jsEnabled) {
+  $(document).ready(function() {
+    Drupal.dateTimeAutoAttach();
+  });
+}', 'inline');
   // Date settings:
   $zones = _system_zonelist();
 
@@ -800,6 +814,8 @@ function system_date_time_settings() {
     $datelongchoices[$f] = format_date(time(), 'custom', $f);
   }
 
+  $datelongchoices['custom'] = $datemediumchoices['custom'] = $dateshortchoices['custom'] = t('Custom format');
+
   $form['date_default_timezone'] = array(
     '#type' => 'select',
     '#title' => t('Default time zone'),
@@ -816,30 +832,68 @@ function system_date_time_settings() {
     '#description' => t('Enable or disable user-configurable time zones. When enabled, users can set their own time zone and dates will be updated accordingly.')
   );
 
+  $date_format_short = variable_get('date_format_short', $dateshort[1]);
   $form['date_format_short'] = array(
+    '#prefix' => '<div class="date-container"><div>',
+    '#suffix' => '</div>',
     '#type' => 'select',
     '#title' => t('Short date format'),
-    '#default_value' => variable_get('date_format_short', $dateshort[1]),
+    '#default_value' => (isset($dateshortchoices[$date_format_short])? $date_format_short : 'custom'),
     '#options' => $dateshortchoices,
     '#description' => t('The short format of date display.')
   );
 
+  $default_short_custom = variable_get('date_format_short_custom', (isset($dateshortchoices[$date_format_short])? $date_format_short : '')); 
+  $form['date_format_short_custom'] = array(
+    '#prefix' => '<div id="short-custom-div">',
+    '#suffix' => '</div></div>',
+    '#type' => 'textfield',
+    '#title' => t('Custom short date format'),
+    '#default_value' => $default_short_custom,
+    '#description' => t('A user-defined short date format. See the <a href="@url">PHP manual</a> for available options. This format is currently set to display as <span>%date</span>.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_short_custom))),
+  );
+
+  $date_format_medium = variable_get('date_format_medium', $datemedium[1]);
   $form['date_format_medium'] = array(
+    '#prefix' => '<div class="date-container"><div>',
+    '#suffix' => '</div>',
     '#type' => 'select',
     '#title' => t('Medium date format'),
-    '#default_value' => variable_get('date_format_medium', $datemedium[1]),
+    '#default_value' => (isset($datemediumchoices[$date_format_medium])? $date_format_medium : 'custom'),
     '#options' => $datemediumchoices,
-    '#description' => t('The medium sized date display.')
+    '#description' => t('The medium sized date display.'),
+  );
+  $default_medium_custom = variable_get('date_format_medium_custom', (isset($datemediumchoices[$date_format_medium])? $date_format_medium : ''));
+  $form['date_format_medium_custom'] = array(
+    '#prefix' => '<div id="medium-custom-div">',
+    '#suffix' => '</div></div>',
+    '#type' => 'textfield',
+    '#title' => t('Custom medium date format'),
+    '#default_value' => $default_medium_custom,
+    '#description' => t('A user-defined medium date format. See the <a href="@url">PHP manual</a> for available options. This format is currently set to display as <span>%date</span>.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_medium_custom))),
   );
 
+  $date_format_long = variable_get('date_format_long', $datelong[0]);
   $form['date_format_long'] = array(
+    '#prefix' => '<div class="date-container"><div>',
+    '#suffix' => '</div>',
     '#type' => 'select',
     '#title' => t('Long date format'),
-    '#default_value' => variable_get('date_format_long', $datelong[0]),
+    '#default_value' => (isset($datelongchoices[$date_format_long])? $date_format_long : 'custom'),
     '#options' => $datelongchoices,
     '#description' => t('Longer date format used for detailed display.')
   );
 
+  $default_long_custom = variable_get('date_format_long_custom', (isset($datelongchoices[$date_format_long])? $date_format_long : ''));
+  $form['date_format_long_custom'] = array(
+    '#prefix' => '<div id="long-custom-div">',
+    '#suffix' => '</div></div>',
+    '#type' => 'textfield',
+    '#title' => t('Custom long date format'),
+    '#default_value' => $default_long_custom,
+    '#description' => t('A user-defined long date format. See the <a href="@url">PHP manual</a> for available options. This format is currently set to display as <span>%date</span>.', array('@url' => 'http://php.net/manual/function.date.php', '%date' => format_date(time(), 'custom', $default_long_custom))),
+  );
+
   $form['date_first_day'] = array(
     '#type' => 'select',
     '#title' => t('First day of week'),
@@ -851,6 +905,30 @@ function system_date_time_settings() {
   return system_settings_form($form);
 }
 
+function system_date_time_settings_submit($form_id, $form_values) {
+  if ($form_values['date_format_short'] == 'custom') {
+    $form_values['date_format_short'] = $form_values['date_format_short_custom'];
+  }
+  if ($form_values['date_format_medium'] == 'custom') {
+    $form_values['date_format_medium'] = $form_values['date_format_medium_custom'];
+  }
+  if ($form_values['date_format_long'] == 'custom') {
+    $form_values['date_format_long'] = $form_values['date_format_long_custom'];
+  }
+  return system_settings_form_submit($form_id, $form_values);
+}
+
+/**
+ * Return the date for a given format string via Ajax.
+ */
+function system_date_time_lookup($format = '') {
+  // Format needs to be decoded a second time for slashes to transmit properly.
+  $format = urldecode($format);
+  $result = format_date(time(), 'custom', $format);
+  echo drupal_to_js(array('response' => $result));
+  exit;
+}
+
 function system_site_maintenance_settings() {
 
   $form['site_offline'] = array(
