PDA

View Full Version : دانلود ماژول تبدیل تاریخ میلادی به شمسی و قمری



A-freeman
25-09-2008, 21:38
ماژول قمری به سادگی تو اینترنت پیدا نمیشه. به هر حال هر دو ماژول تبدیل میلادی به شمسی و قمری رو رو می تونید از زیر بردارید:

میلادی به شمسی:

$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);

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

$div = create_function('$a,$b','return (int) ($a / $b);');

$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); /* 12053 = 365*33 + 32/4 */
$j_day_no = $j_day_no % 12053;

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

$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);
}




میلادی به قمری:


/*
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA

Note:

The Hijridate PHP Script is released under the GNU Public license so you are free to develop
anything with this script, however YSE would appreciate being informed so that they can
add your script to their list.

** YSE:
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید | support@yse-uk.com **

** Usayd Network:
برای مشاهده محتوا ، لطفا وارد شوید یا ثبت نام کنید **

*/

$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);

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

$div = create_function('$a,$b','return (int) ($a / $b);');

$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); /* 12053 = 365*33 + 32/4 */
$j_day_no = $j_day_no % 12053;

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

$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 hijriDate() {
$timestamp = time();
$timestamp += bstOffset($timestamp) * 3600;

$thisYear = strftime("%Y", $timestamp);
$thisMonth = strftime("%m", $timestamp);
if($thisMonth < 10)
$thisMonth = substr($thisMonth, 1, 1);
$thisDay = trim(strftime("%e", $timestamp));

$greg_part = strftime("%d %B %YCE", $timestamp);

$hijri_date = jd2hijri(greg2jd($thisDay, $thisMonth, $thisYear));
$hijri_part = sprintf("%02d %s %d", $hijri_date[0],
hijrimonth2name($hijri_date[1]), $hijri_date[2]);

$day=round($hijri_date[0]);
$monyh=hijrimonth2name($hijri_date[1]);
$year=$hijri_date[2];
$date=array($day,$monyh,$year);
return $date;

//return $greg_part . ' | ' . $hijri_part;
}

function greg2jd($d, $m, $y) {
$jd = (1461 * ($y + 4800 + ($m - 14) / 12)) / 4 +
(367 * ($m - 2 - 12 * (($m - 14) / 12))) / 12 -
(3 * (($y + 4900 + ($m - 14) / 12) / 100 )) / 4 +
$d - 32075;

return $jd;
}

function jd2hijri($jd) {
$jd = $jd - 1948440 + 10632;
$n = (int) (($jd - 1) / 10631);
$jd = $jd - 10631 * $n + 354;
$j = ((int) ((10985 - $jd) / 5316)) *
((int) (50 * $jd / 17719)) +
((int) ($jd / 5670)) *
((int) (43 * $jd / 15238));
$jd = $jd - ((int) ((30 - $j) / 15)) *
((int) ((17719 * $j) / 50)) -
((int) ($j / 16)) *
((int) ((15238 * $j) / 43)) + 29;
$m = (int) (24 * $jd / 709);
$d = $jd - (int) (709 * $m / 24);
$y = 30 * $n + $j - 30;

return array($d, $m, $y);
}

function hijrimonth2name($m) {
switch($m) {
case 1:
return 'محرم';
case 2:
return 'صفر';
case 3:
return 'ربیع الاول';
case 4:
return 'ربیع الثانی';
case 5:
return 'جمادی الاولی';
case 6:
return 'جمادی الثانی';
case 7:
return 'رجب';
case 8:
return 'شعبان';
case 9:
return 'رمضان';
case 10:
return 'شوال';
case 11:
return 'ذی قعده';
case 12:
return 'ذی حجه';
}
}


function bstOffset($currDate) {
$thisYear = (date("Y"));
$marStartDate = ($thisYear."-03-25");
$octStartDate = ($thisYear."-10-25");
$marEndDate = ($thisYear."-03-31");
$octEndDate = ($thisYear."-10-31");


while ($marStartDate <= $marEndDate) {
$day = date("l", strtotime($marStartDate));
if ($day == "Sunday")
$bstStartDate = $marStartDate;
$marStartDate++;
}


$bstStartDate = (date("U", strtotime($bstStartDate))+(60*60));


while($octStartDate <= $octEndDate) {
$day = date("l", strtotime($octStartDate));
if ($day == "Sunday")
$bstEndDate = $octStartDate;
$octStartDate++;
}

$bstEndDate = (date("U", strtotime($bstEndDate))+(60*60));

if($currDate < $bstEndDate && $currDate > $bstStartDate)
return 1;
else
return 0;
}


نحوه استفاده از قمری:

$hejri=hijriDate();
$day=$hejri[0];
$month=$hejri[1];
$year=$hejri[2];


نحوه استفاده از شمسی:

$t=time();
//echo(date("D F d Y",$t)); >> Mon January 30 2006

$year=date("Y",$t);
$month=date("F",$t);
$day=date("d",$t);

$shamsy=gregorian_to_jalali($year,$month,$day);
$day=$shamsy[2];
$month=$shamsy[1];
$year=$shamsy[0];