Patch for Buddhist era in Drupal
Submitted by sugree on Fri, 12/21/2007 - 12:16.
I got a request to fix problem regarding lack of Buddhist era in Drupal for so long. This should be classified as a bug of PHP and Drupal. PHP provides only strftime() which recognizes locale setting, setlocale(). Unfortunately, Drupal uses only gmdate(). That's the problem. So I have to patch common.inc to handle Y and y alternatively.
I have filed this issue to Drupal at #202891 and hope it will be applied to Drupal 6 before final release. To use this feature, you need to add below line to settings.php.
setlocale(LC_CTIME, 'th_TH.UTF8');
Moreover, you might need to ask your hosting provider to generate locale th_TH.UTF8 and restart httpd to activate the new locale.
Drupal 5.x
--- common.inc.orig 2007-12-21 11:30:00.979219418 +0700 +++ common.inc 2007-12-21 11:28:21.795715583 +0700 @@ -1092,7 +1092,14 @@ if (strpos('AaDFlM', $c) !== FALSE) { $date .= t(gmdate($c, $timestamp)); } - else if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c) !== FALSE) { + else if (strpos('Yy', $c) !== FALSE) { + $y = strftime('%Ey', $timestamp); + if ($c == 'y') { + $y .= substr($y, -2); + } + $date .= $y; + } + else if (strpos('BdgGhHiIjLmnsStTUwWz', $c) !== FALSE) { $date .= gmdate($c, $timestamp); } else if ($c == 'r') {
Drupal 6.x
--- common.inc.orig 2007-12-21 11:38:31.000000000 +0700 +++ common.inc 2007-12-21 11:38:52.000000000 +0700 @@ -1186,7 +1186,14 @@ // different abbreviations. $date .= trim(t('!long-month-name '. gmdate($c, $timestamp), array('!long-month-name' => ''), $langcode)); } - else if (strpos('BdgGhHiIjLmnsStTUwWYyz', $c) !== FALSE) { + else if (strpos('Yy', $c) !== FALSE) { + $y = strftime('%Ey', $timestamp); + if ($c == 'y') { + $y .= substr($y, -2); + } + $date .= $y; + } + else if (strpos('BdgGhHiIjLmnsStTUwWz', $c) !== FALSE) { $date .= gmdate($c, $timestamp); } else if ($c == 'r') {





Post new comment