|  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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: satovey at yahoo dot com
New email:
PHP Version: OS:


 [2013-08-28 23:08 UTC] satovey at yahoo dot com
From manual page:

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:

  $year = "5777";
  $firstDate = "1/1/$year";
  $lastDate = "13/30/$year";
  calculateTotalDays($firstDate, $lastDate, $year, $count);
  $firstDate = "1/1/$year";
  $lastDate = "13/29/$year";
  calculateTotalDays($firstDate, $lastDate, $year, $count);
 function calculateTotalDays($firstDate, $lastDate, $year, $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.

>> 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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-08-29 02:53 UTC]
-Status: Open +Status: Not a bug -Package: Built-in web server +Package: Calendar related
 [2013-08-29 02:53 UTC]
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 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 

$totalDaysInYear = $lastDay - $firstDay + 1;
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 13 17:01:32 2024 UTC