Jump to content

Persian (Iranian) Date Format


Guest mehrdad

Recommended Posts

Guest mehrdad

Hi everyone,

 

I am working on a classifieds ad website which is writen in PHP.

 

When a user posts an ad, the script picks todays date and put it in together with the ad. For example: Created on "Sunday, June 12, 2007"

 

I want the script to stamp user's ads with a different date format, an Iranian Date format (Jalili Calendar) which is a different calendar. For Example: "Sunday, Tir 22, 1386"

 

Below is the calendar.php file which also shows a date picker on the screen which it's not my main concern at the moment. The only concern I have is the date that comes with every post. Just like emails where there is a date on the header of each email.

 

I was wondering if there is anyone here with a very good knowledge and underestanding of different calendar systems who can help me deploy this changes with my current script. I really appreciate your ideas and feedbacks.

 

Any idea?

 

 

 



<?php



class calendar

{

function display($urlformat, $weekday_start=0, $weekdays="", $months="", $year=0, $month=0, $specialdates="", $cellwidth=20)

{

	// Get year and month

	if($year && $month)

	{

		$day = date("d");

		$t = mktime(0, 0, 0, $month, $day, $year);

		if($year == date("Y") && $month == date("m")) $highlighttoday = TRUE;

	}

	else

	{

		$year = date("Y");

		$month = date("m");

		$day = date("d");

		$t = time();

		$highlighttoday = TRUE;

	}



	// Save year and month

	//setcookie("_xzcal_m", $month);

	//setcookie("_xzcal_y", $year);



	// Get weekday and month names

	if(!$weekdays)

	{

		$weekdays = array("Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday");

	}



	if(!$months)

	{

		$months = array("January","February","March","April","May","June","July","August","September","October","November","December");

	}



	$weekdays_small = array();

	foreach($weekdays as $k=>$wd)

	{

		$weekdays_small[$k] = substr($wd, 0, 1);

		if(ord($weekdays_small[$k]) >= 128) $weekdays_small[$k] .= substr($wd, 1, 1);

	}





	// Calendar title

	$caltitle = $months[$month-1] . " " . $year;



	// Prev and next month links

	if ($month == 1)

	{

		$prev_month = 12;

		$prev_month_year = $year-1;

	}

	else

	{

		$prev_month = $month-1;

		$prev_month_year = $year;

	}



	if ($month == 12)

	{

		$next_month = 1;

		$next_month_year = $year+1;

	}

	else

	{

		$next_month = $month+1;

		$next_month_year = $year;

	}





	$month_link = "?";

	$qsA = $_GET; unset($qsA['_xzcal_m'], $qsA['_xzcal_y']);

	foreach($qsA as $k=>$v) $month_link .= "$k=$v&";

	$prev_month_link = $month_link . "_xzcal_m=$prev_month&_xzcal_y=$prev_month_year";

	$next_month_link = $month_link . "_xzcal_m=$next_month&_xzcal_y=$next_month_year";





	$cal = <<< EOB

	<table cellspacing="1" border="0" cellpadding="0" class="calendar">

	<tr>

	<td class="cal_header_month"><a href="$prev_month_link">«</a></td>

	<td colspan="5" class="cal_header_month">$caltitle</td>

	<td class="cal_header_month"><a href="$next_month_link">»</a></td>

	</tr>

	<tr>



EOB;



	// Weekdays

	$j = $weekday_start;

	for ($i=0; $i<7; $i++)

	{

		$wds = $weekdays_small[$j];



		$cal .= <<< EOB

		<td class="cal_header_week" width="$cellwidth">$wds</td>



EOB;

		$j++;

		if ($j==7) $j=0;

	}



	$cal .= <<< EOB

	</tr>

EOB;





	// Days

	$firstday_weekday = date("w", mktime(0, 0, 0, $month, 1, $year));



	$empty_cells = ($firstday_weekday >= $weekday_start) ? 

					($firstday_weekday - $weekday_start) : 

					7 - $weekday_start;



	if ($empty_calls) $cal .= "<tr>";

	for ($i=0; $i<$empty_cells; $i++)

		$cal .= "<td> </td>";



	$lastday = date("t", $t);

	//$datepre = date("Y-m-", $t);

	$today = date("j", $t);



	for ($d=1; $d<=$lastday; $d++, $i++)

	{

		$url = $urlformat;

		$url = str_replace("{@T}", mktime(0, 0, 0, $month, $d, $year), $url);

		$url = str_replace("{@D}", str_pad($d, 2, "0", STR_PAD_LEFT), $url);

		$url = str_replace("{@M}", $month, $url);

		$url = str_replace("{@Y}", $year, $url);

		$url = str_replace("{@W}", $i, $url);



		if ($i%7==0) $cal .= "<tr>";

		$cal .= "<td";

		if ($d == $today && $highlighttoday) $cal .= " id=\"today\"";

		if ($specialdates[$d]) $cal .= " class=\"content_date\"";

		$cal .= "><a href=\"$url\">$d</a></td>";

		if ($i%7==6) $cal .= "</tr>";

	}



	if ($i%7 != 0)

	{

		for(; $i%7!=0; $i++) $cal .= "<td> </td>";

	}



	$cal .= "</tr></table>";



	echo $cal;



}

}



?>


Link to comment
https://forums.phpfreaks.com/topic/56049-persian-iranian-date-format/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.