Jalali date

Hadi Farnoud - February 8, 2008 - 10:51
Project:Date
Version:7.x-1.x-dev
Component:Date API
Category:feature request
Priority:normal
Assigned:Hadi Farnoud
Status:needs work
Description

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

?>

#1

Hadi Farnoud - February 27, 2008 - 13:28
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

#2

KarenS - September 5, 2008 - 13:21
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.

#3

lameei - March 4, 2009 - 11:02

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.

#4

Hadi Farnoud - March 6, 2009 - 12:20
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

#5

lameei - March 8, 2009 - 06:23

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?

#6

Hadi Farnoud - August 27, 2009 - 09:39

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 :)

#7

lameei - August 27, 2009 - 10:09

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

#8

Hadi Farnoud - November 3, 2009 - 16:40

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

 
 

Drupal is a registered trademark of Dries Buytaert.