php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65578 Php Calendar does not calculate number of days correctly
Submitted: 2013-08-28 23:08 UTC Modified: 2013-08-29 02:53 UTC
From: satovey at yahoo dot com Assigned:
Status: Not a bug Package: Calendar related
PHP Version: Irrelevant OS: Windows 7
Private report: No CVE-ID: None
 [2013-08-28 23:08 UTC] satovey at yahoo dot com
Description:
------------
---
From manual page: http://www.php.net/function.jewishtojd
---

In using the JewishToJD function of the Calendar,
there is a discrepancy in the total days of the year.
The last month of the Jewish Year has 29 days 
and the shortest year is 353 days.


Test script:
---------------
<?PHP

  $year = "5777";
  $firstDate = "1/1/$year";
  $lastDate = "13/30/$year";
  $count=1;
  calculateTotalDays($firstDate, $lastDate, $year, $count);
 
  $firstDate = "1/1/$year";
  $lastDate = "13/29/$year";
  $count=1;
  calculateTotalDays($firstDate, $lastDate, $year, $count);
 
 function calculateTotalDays($firstDate, $lastDate, $year, $count)
 {
	$count++;
	$displayYear = $year;
	list($firstMonth, $firstDay, $firstYear) = explode("/",$firstDate);
	list($lastMonth, $lastDay, $lastYear) = explode("/",$lastDate);
	if ($year < 0)
	{
		$firstYear = $firstYear + 248;
		$lastYear = $lastYear + 248;
		//echo "less than 0 => $year<br />";
	}
	$firstDay = jewishtojd( $firstMonth, $firstDay, $firstYear );
	$lastDay = jewishtojd ( $lastMonth, $lastDay, $lastYear );
	$totalDaysInYear = $lastDay - $firstDay;
	//echo "$firstDate, $lastDate <br />";
	//echo "Cycle Count -> $count | Total Days in the Year $year => ";
	echo "$displayYear ";
	echo "$totalDaysInYear";
	echo "<br />";
 }

?>

Expected result:
----------------
It is expected that when calculating between 1/1/577 to 13/29/577 the 
return should be 353 days as that is the number of days in the Jewish
year 5777.

http://en.wikipedia.org/wiki/Hebrew_calendar#Leap_years

>> Scroll up to see a list of new year dates. <<

This appears to occur in all versions of PHP.



Actual result:
--------------
Yet the provided code will output 352 days if 13,29,5777 is entered
and 353 days if 13,30,5777 is entered. Note: the month of Elul which
is given the number 13 is a 29 day month.

The output is as follows:

5777 353
5777 352

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-29 02:53 UTC] requinix@php.net
-Status: Open +Status: Not a bug -Package: Built-in web server +Package: Calendar related
 [2013-08-29 02:53 UTC] requinix@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

Your arithmetic is off by one: using January to demonstrate, you're subtracting 
January 31st minus January 1st and concluding that there are 31-1=30 days in the 
month.

$totalDaysInYear = $lastDay - $firstDay + 1;
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 12:01:31 2024 UTC