php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #52972 Support Persian Calendar
Submitted: 2010-10-02 19:54 UTC Modified: 2017-08-13 00:56 UTC
Votes:3
Avg. Score:3.7 ± 0.9
Reproduced:3 of 3 (100.0%)
Same Version:3 (100.0%)
Same OS:3 (100.0%)
From: takmahdi at gmail dot com Assigned:
Status: Suspended Package: Calendar related
PHP Version: 5.3.3 OS: Linux/Windows
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2010-10-02 19:54 UTC] takmahdi at gmail dot com
Description:
------------
Hi,

I want use Persian calendar in PHP, but not support this feature; In Iran we use 
none standard script for implement this feature and It is not likely...!
If year%33 remaining 1, 5, 9, 13, 17, 22, 26, 30 this year will calling leap 
year.

Persian calendar:
months/abbrevmonths are: Farvardin, Ordibehesht, Khordad, Tir, Mordad, 
Shahrivar, Mehr, Aban, Azar, Dey, Bahman, Esfand
daysname/abbrevdaysname: Yekshanbeh = Sunday, Doshanbeh, Seshhanbeh, 
Chaharshanbeh, Panjshanbeh, Jomeh, Shanbeh
week begin from Shanbeh
days range in month: 29-31

I use below script:
http://www.fourmilab.ch/documents/calendar/

Thanks for cooperation.
Regards

Test script:
---------------
const CAL_PERSIAN = 4;
const PERSIAN_EPOCH = 1948320.5;
function Persian2JD($year, $month, $day) {
	$epbase = $year - (($year >= 0) ? 474 : 473);
	$epyear = 474 + $epbase%2820;
	return $day + (($month <= 7) ? (($month - 1) * 31) : ((($month - 1) * 
30) + 6)) + (int)((($epyear * 682) - 110) / 2816) + ($epyear - 1) * 365 + 
(int)($epbase / 2820) * 1029983 + (PERSIAN_EPOCH - 1);
}
function JD2Persian($jd) { # Calculate Persian date from Julian day
	$jd = (int)$jd + 0.5;

	$depoch = $jd - Persian2JD(475, 1, 1);
	$cycle = (int)($depoch / 1029983);
	$cyear = $depoch%1029983;
	if ($cyear == 1029982)
		$ycycle = 2820;
	else {
		$aux1 = (int)($cyear / 366);
		$aux2 = $cyear%366;
		$ycycle = (int)(((2134 * $aux1) + (2816 * $aux2) + 2815) / 
1028522) + $aux1 + 1;
	}
	$year = $ycycle + (2820 * $cycle) + 474;
	if ($year <= 0)
		$year--;
	$yday = ($jd - Persian2JD($year, 1, 1)) + 1;
	$month = ($yday <= 186) ? ceil($yday / 31) : ceil(($yday - 6) / 30);
	$day = ($jd - Persian2JD($year, $month, 1)) + 1;
	return $year.'-'.str_pad($month, 2, 0, STR_PAD_LEFT).'-'.str_pad($day, 
2, 0, STR_PAD_LEFT);
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-13 00:56 UTC] cmb@php.net
-Status: Open +Status: Suspended
 [2017-08-13 00:56 UTC] cmb@php.net
Thank you for your interest in PHP and for submitting a feature
request. Please be aware that due to the magnitude of change this
request requires, it would be necessary to discuss it on PHP
Internals list (internals@lists.php.net) as an RFC. Please read
the guide about creating RFCs here:
<https://wiki.php.net/rfc/howto>. If you haven't had experience
with writing RFCs before, it is advised to seek guidance on the
Internals list (<http://php.net/mailing-lists.php>) and/or solicit
help from one of the experienced developers. 

Please do not consider this comment as a negative view on the
merits of your proposal – every proposal which requires changes of
certain magnitude, even the very successful and widely supported
ones, must be done through the RFC process. This helps make the
process predictable, transparent and accessible to all developers.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC