Better patch for Buddhist era in Drupal
Submitted by sugree on Sat, 12/22/2007 - 13:10.After the first patching attempt to display Buddhist era in Drupal correctly, I found an annoying issue as a result at Drupal Thailand while trying to edit my own comment. The node's date is formatted by format_date() using custom format with Y. Unfortunately, the date string is converted back to seconds using strtotime() which doesn't recognize Buddhist era, says 2550. I had to change 2550 to 2007 to save that comment.
After thinking for a while, I found better solution by adding 'X' and 'x' for localized year like Buddhist era and let users specify custom date formats in settings.php.
settings.php
setlocale(LC_TIME, 'th_TH.UTF8'); $conf = array( 'date_format_short' => 'm/d/X - H:i', 'date_format_large' => 'l, F j, X - H:i', 'date_format_medium' => 'D, m/d/X - H:i', );
Drupal 5.x
--- common.inc.orig 2007-10-18 04:28:59.000000000 +0700 +++ common.inc 2007-12-22 12:21:39.095886667 +0700 @@ -1092,6 +1092,13 @@ if (strpos('AaDFlM', $c) !== FALSE) { $date .= t(gmdate($c, $timestamp)); } + else if (strpos('Xx', $c) !== FALSE) { + $y = strftime('%Ey', $timestamp); + if ($c == 'x') { + $y .= substr($y, -2); + } + $date .= $y; + } else if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c) !== FALSE) { $date .= gmdate($c, $timestamp); }
Drupal 6.x
--- common.inc.orig 2007-12-22 12:45:55.000000000 +0700 +++ common.inc 2007-12-22 12:46:10.000000000 +0700 @@ -1186,6 +1186,13 @@ // different abbreviations. $date .= trim(t('!long-month-name '. gmdate($c, $timestamp), array('!long-month-name' => ''), $langcode)); } + else if (strpos('Xx', $c) !== FALSE) { + $y = strftime('%Ey', $timestamp); + if ($c == 'x') { + $y .= substr($y, -2); + } + $date .= $y; + } else if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c) !== FALSE) { $date .= gmdate($c, $timestamp); }




