Sugree

Main menu

  • About
    • Self
  • Project
    • Barcode Generator / Reader
    • GT200
    • GeoPin
    • Mitter
    • Red Mob
    • Thairath Breaking News
    • Twitter Android SDK
    • jibjib
    • microblog-purple
    • 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);
     }
Roti (alpha) thinks you may like these:
  • Better life, Better world
  • Better Busy, Better
  • Be the better man!
  • For Better or For Worse
  • Better Together
  • Login to post comments
by mk (not verified) on Fri, 02/13/2009 - 11:40 #828

เสนอ format date แบบไทยๆ ด้วย

'date_format_short' => 'j M X - H:i',
'date_format_large' => 'l j F X - H:i',
'date_format_medium' => 'j F X - H:i',
  • Login to post comments

Popular Tags

Android BarCamp BarCampBangkok Book Django Drupal Education Family Google Hardware Hardy Health Interview Intrepid Java jibjib Joke Life microblog-purple OpenOffice.org OpenSource Podcast Python Review SoC Social Network Trip Twitter Ubuntu Weekly Suki
more tags

Powered By

debian
apache
drupal
drupal.in.th
openfreehost
inox
feedburner

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