Sugree

Main menu

  • About
    • Self
  • Project
    • jibjib
    • microblog-purple
    • Mitter
  • English
  • Thai

Better patch for Buddhist era in Drupal

Submitted by sugree on Sat, 12/22/2007 - 13:10.
  • Drupal
  • English
  • Patch

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);
     }

Reply

The content of this field is kept private and will not be shown publicly.
Input format
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockcode> <pre>
  • Lines and paragraphs break automatically.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use Markdown syntax to format and style the text.

More information about formatting options

Popular Tags

Assumption BarCamp BarCampBangkok BarCampBangkok2 BarCampBkk2 Creature Drupal DrupalCamp DrupalCampBangkok Education Family Google Hardware Hardy Health Java JibCafe jibjib Joke NokNok OpenOffice.org Python Review SoC Social Network Trip TwittBKK TwittDay Twitter Ubuntu
more tags

Powered By

debian
apache
drupal
drupal.in.th
feedburner

© 2007-2008 Sugree Phatanapherom. Creative Commons [Feed Content / Comment]
RoopleTheme