Sugree

Main menu

  • About
  • Project
    • 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);
     }

Post new comment

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>, <html>. 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>, <html>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • You can use Markdown syntax to format and style the text. Also see and Markdown Extra for tables, footnotes, and more.
  • Twitter-style @usersnames are linked to their Twitter account pages.
  • Twitter-style #hashtags are linked to search.twitter.com.

More information about formatting options

Popular Tags

Assumption BarCamp BarCampBangkok BarCampBangkok2 BarCampBkk2 Django Drupal DrupalCamp DrupalCampBangkok Education Family Google Hardware Hardy Health Java jibjib Joke NokNok OpenOffice.org OpenSource Podcast Python Review SoC Social Network Trip Twitter Ubuntu Weekly Suki
more tags

Powered By

debian
apache
drupal
drupal.in.th
feedburner

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