Make your own free website on Tripod.com
<?php

/*
    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: www.yse-uk.com | support@yse-uk.com **

    ** Usayd Network: www.usayd.com **

*/

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 %dAH", $hijri_date[0],
	hijrimonth2name($hijri_date[1]), $hijri_date[2]);

	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 'Muharram';
		case 2:
			return 'Safar';
		case 3:
			return 'Rabbi al-Awwal';
		case 4:
			return 'Rabbi al-Thanni';
		case 5:
			return 'Jumada al-Ula';
		case 6:
			return 'Jumada al-Thanni';
		case 7:
			return 'Rajab';
		case 8:
			return 'Shaban';
		case 9:
			return 'Ramadhan';
		case 10:
			return 'Shawwal';
		case 11:
			return 'Dhul-Qadah';
		case 12:
			return 'Dhul-Hijjah';
	}
}


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