please add jalali date format,

<?php 
$g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
$j_month_name = array("", "Farvardin", "Ordibehesht", "Khordad", "Tir",
                      "Mordad", "Shahrivar", "Mehr", "Aban", "Azar",
                      "Dey", "Bahman", "Esfand");

function div($a, $b)
{
   return (int) ($a / $b);
}
  
function gregorian_to_jalali($g_y, $g_m, $g_d)
{
   global $g_days_in_month;
   global $j_days_in_month;
   
   $gy = $g_y-1600;
   $gm = $g_m-1;
   $gd = $g_d-1;

   $g_day_no = 365*$gy+div($gy+3,4)-div($gy+99,100)+div($gy+399,400);

   for ($i=0; $i < $gm; ++$i)
      $g_day_no += $g_days_in_month[$i];
   if ($gm>1 && (($gy%4==0 && $gy%100!=0) || ($gy%400==0)))
      /* leap and after Feb */
      ++$g_day_no;
   $g_day_no += $gd;

   $j_day_no = $g_day_no-79;

   $j_np = div($j_day_no, 12053);
   $j_day_no %= 12053;

   $jy = 979+33*$j_np+4*div($j_day_no,1461);

   $j_day_no %= 1461;

   if ($j_day_no >= 366) {
      $jy += div($j_day_no-1, 365);
      $j_day_no = ($j_day_no-1)%365;
   }

   for ($i = 0; $i < 11 && $j_day_no >= $j_days_in_month[$i]; ++$i) {
      $j_day_no -= $j_days_in_month[$i];
   }
   $jm = $i+1;
   $jd = $j_day_no+1;


   return array($jy, $jm, $jd);
}

function farsinum($str)
{
  if (strlen($str) == 1)
      $str = "0".$str;
  $out = "";
  for ($i = 0; $i < strlen($str); ++$i) {
    $c = substr($str, $i, 1);
    $out .= pack("C*", 0xDB, 0xB0 + $c);
  }
  return $out;
}

function date_format($datestamp)
{
  $tzoffset = 0;
  list($date,$time) = explode(" ",$datestamp);
  list($year,$month,$day) = explode("-",$date);
  list($hour,$minute,$second) = explode(":",$time);
  $hour = $hour + $tzoffset;

  list($jyear, $jmonth, $jday) = gregorian_to_jalali($year,$month,$day);

  $sDate = farsinum($jyear - 1300)."/".farsinum($jmonth)."/".farsinum($jday)
           ."&nbsp;&nbsp;".farsinum($hour).":".farsinum($minute);
    
  return "<span lang='fa' dir='rtl'>" . $sDate . "</span>";
}

?>
CommentFileSizeAuthor
#9 jalali.zip6.72 KBhadi farnoud

Comments

hadi farnoud’s picture

Priority: Critical » Normal
Status: Reviewed & tested by the community » Needs work

Priority wasn't critical but we can't run a persian website without Jalali date! please review

karens’s picture

Version: 5.x-1.x-dev » 6.x-2.x-dev

I'm not making changes to the 5.1 version. I'm officially recommending you move to the 5.2 version now. If you have problems in that version you can check for existing issues or add new ones. Feature requests are now getting posted to the D6 version to be back-ported to 5.2.

I'll bump this ahead, but still don't know any way that this could be incorporated without a complete re-write of the Date module. If someone sees a way, I'll look at patches.

lameei’s picture

Karen
Have you did anything about Jalali date. I've read locale based handling and rendering and i think it is a good start for adding new features to Drupal date. I'm a newbie in php so I don't know what i can do.

hadi farnoud’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev

Maybe it's better to add Jalali Date to 7.x before it gets public!

In contrast , I can help you with Jalali Date and I know how to help. We need to add this feature while 7.x is not released

lameei’s picture

It is good idea for adding Jalali Date to 7.x but I think most of the people are using 6.x right now so we need to do something about it.

@hadi: Have you did this for 6.x?

hadi farnoud’s picture

Lameei

I think we can't put it in D6 core. I don't know how can I create a module without touching core codes.

I need great help :)

lameei’s picture

@hadi
check this out. it seems Sina has something to say. http://drupal.org/project/calendar_systems

hadi farnoud’s picture

@lameei
very impressive. I just contact him ASAP. My request is to add this module as a part of Date API

hadi farnoud’s picture

StatusFileSize
new6.72 KB

Can anyone test this module? It needs apd and runs on D6 (For now)

hadi farnoud’s picture

Status: Needs work » Fixed

http://drupal.org/project/calendar_systems offers the functionality I was looking for.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

issauni’s picture

Mine is not working correctly.
Only the year is shown correctly.

Where is the problem?

issauni’s picture

Instead of 89/11/11 for 2011/01/31 it shows 1389/12/317.

I am using D6.

issauni’s picture

I changed it to this and the problem is gone :

<?php

function div($a, $b)
{
return (int) ($a / $b);
}

function gregorian_to_jalali($g_y, $g_m, $g_d)
{
// global $g_days_in_month;
// global $j_days_in_month;

$g_days_in_month = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$j_days_in_month = array(31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29);
$j_month_name = array("", "Farvardin", "Ordibehesht", "Khordad", "Tir",
"Mordad", "Shahrivar", "Mehr", "Aban", "Azar",
"Dey", "Bahman", "Esfand");

---------------------------------------------------------------------------------------------------------

I don't know why "global" doesn't work. Those three arrays were undefined inside the function, using "global". Maybe I should enable something in D6 to be able to use "global".

hadi farnoud’s picture

Have a look at Calendar system module