Index: token.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/token/token.module,v
retrieving revision 1.7.4.45
diff -u -p -r1.7.4.45 token.module
--- token.module	19 Nov 2010 23:11:55 -0000	1.7.4.45
+++ token.module	7 Dec 2010 18:47:59 -0000
@@ -484,45 +484,114 @@ function token_get_date_token_info($desc
 
 /**
  * Build a list of common date tokens for use in hook_token_values().
- *
- * @param $description
  */
-function token_get_date_token_values($timestamp = NULL, $token_prefix = '') {
-  $tokens = array();
+function token_get_date_token_values($timestamp = NULL, $token_prefix = '', $langcode = NULL) {
+  static $formats;
+
+  if (!isset($formats)) {
+    $formats = array(
+      'yyyy' => 'Y',
+      'yy' => 'y',
+      'month' => 'F',
+      'mon' => 'M',
+      'mm' => 'm',
+      'm' => 'n',
+      'ww' => 'W',
+      'date' => 'N', // PHP 5.1 only.
+      'day' => 'l',
+      'ddd' => 'D',
+      'dd' => 'd',
+      'd' => 'j',
+    );
+    if (!version_compare(PHP_VERSION, '5.1.0', '>=')) {
+      unset($formats['date']);
+    }
+  }
+
   $time = time();
   if (!isset($timestamp)) {
     $timestamp = $time;
   }
-  $timezone = variable_get('date_default_timezone', 0);
 
-  $formats = array(
-    'yyyy' => 'Y',
-    'yy' => 'y',
-    'month' => 'F',
-    'mon' => 'M',
-    'mm' => 'm',
-    'm' => 'n',
-    'ww' => 'W',
-    //'date' => 'N', // Provided later since it is PHP 5.1 only.
-    'day' => 'l',
-    'ddd' => 'D',
-    'dd' => 'd',
-    'd' => 'j',
-  );
+  $tokens = array();
   foreach ($formats as $token => $format) {
-    $tokens[$token_prefix . $token] = format_date($timestamp, 'custom', $format, $timezone);
+    $tokens[$token_prefix . $token] = token_format_date($timestamp, 'custom', $format, NULL, $langcode);
   }
-
-  $tokens[$token_prefix . 'small'] = format_date($timestamp, 'small', '', $timezone);
+  $tokens[$token_prefix . 'small'] = token_format_date($timestamp, 'small', '', NULL, $langcode);
   $tokens[$token_prefix . 'raw'] = $timestamp;
-  $tokens[$token_prefix . 'since'] = format_interval($time - $timestamp, 2);
+  $tokens[$token_prefix . 'since'] = format_interval($time - $timestamp, 2, $langcode);
+
+  return $tokens;
+}
+
+/**
+ * A copy of format_date() that supports the 'N' date format character.
+ *
+ * @see format_date()
+ */
+function token_format_date($timestamp, $type = 'medium', $format = '', $timezone = NULL, $langcode = NULL) {
+  if (!isset($timezone)) {
+    global $user;
+    if (variable_get('configurable_timezones', 1) && $user->uid && strlen($user->timezone)) {
+      $timezone = $user->timezone;
+    }
+    else {
+      $timezone = variable_get('date_default_timezone', 0);
+    }
+  }
 
   $timestamp += $timezone;
-  if (version_compare(PHP_VERSION, '5.1.0', '>=')) {
-    $tokens[$token_prefix . 'date'] = gmdate('N', $timestamp);
+
+  switch ($type) {
+    case 'small':
+      $format = variable_get('date_format_short', 'm/d/Y - H:i');
+      break;
+    case 'large':
+      $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');
+  }
+
+  $max = strlen($format);
+  $date = '';
+  for ($i = 0; $i < $max; $i++) {
+    $c = $format[$i];
+    if (strpos('AaDlM', $c) !== FALSE) {
+      $date .= t(gmdate($c, $timestamp), array(), $langcode);
+    }
+    elseif ($c == 'F') {
+      // Special treatment for long month names: May is both an abbreviation
+      // and a full month name in English, but other languages have
+      // different abbreviations.
+      $date .= trim(t('!long-month-name ' . gmdate($c, $timestamp), array('!long-month-name' => ''), $langcode));
+    }
+    elseif (strpos('BdgGhHiIjLmnNsStTUwWYyz', $c) !== FALSE) {
+      // This condition was modified to allow the 'N' date format character.
+      $date .= gmdate($c, $timestamp);
+    }
+    elseif ($c == 'r') {
+      $date .= token_format_date($timestamp - $timezone, 'custom', 'D, d M Y H:i:s O', $timezone, $langcode);
+    }
+    elseif ($c == 'O') {
+      $date .= sprintf('%s%02d%02d', ($timezone < 0 ? '-' : '+'), abs($timezone / 3600), abs($timezone % 3600) / 60);
+    }
+    elseif ($c == 'Z') {
+      $date .= $timezone;
+    }
+    elseif ($c == '\\') {
+      $date .= $format[++$i];
+    }
+    else {
+      $date .= $c;
+    }
   }
 
-  return $tokens;
+  return $date;
 }
 
 /**
