Closed (fixed)
Project:
Date
Version:
7.x-1.x-dev
Component:
Date API
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
8 Feb 2008 at 10:51 UTC
Updated:
13 Feb 2011 at 21:50 UTC
Jump to comment: Most recent file
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)
." ".farsinum($hour).":".farsinum($minute);
return "<span lang='fa' dir='rtl'>" . $sDate . "</span>";
}
?>
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | jalali.zip | 6.72 KB | hadi farnoud |
Comments
Comment #1
hadi farnoud commentedPriority wasn't critical but we can't run a persian website without Jalali date! please review
Comment #2
karens commentedI'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.
Comment #3
lameei commentedKaren
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.
Comment #4
hadi farnoud commentedMaybe 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
Comment #5
lameei commentedIt 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?
Comment #6
hadi farnoud commentedLameei
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 :)
Comment #7
lameei commented@hadi
check this out. it seems Sina has something to say. http://drupal.org/project/calendar_systems
Comment #8
hadi farnoud commented@lameei
very impressive. I just contact him ASAP. My request is to add this module as a part of Date API
Comment #9
hadi farnoud commentedCan anyone test this module? It needs apd and runs on D6 (For now)
Comment #10
hadi farnoud commentedhttp://drupal.org/project/calendar_systems offers the functionality I was looking for.
Comment #12
issauni commentedMine is not working correctly.
Only the year is shown correctly.
Where is the problem?
Comment #13
issauni commentedInstead of 89/11/11 for 2011/01/31 it shows 1389/12/317.
I am using D6.
Comment #14
issauni commentedI 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".
Comment #15
hadi farnoud commentedHave a look at Calendar system module