Skip to content

Commit

Permalink
Add calculations for number of months in a given year
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Roach committed Sep 17, 2018
1 parent fe3d1e2 commit 7c7d340
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 30 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,9 @@
CHANGE LOG
==========

## 2.5.0 (2018-09-17)
- Calculate number of months in a given year

## 2.4.0 (2018-01-15)
- PHP error messages changed slightly in 7.2.0

Expand Down
7 changes: 5 additions & 2 deletions src/ArabicCalendar.php
Expand Up @@ -111,11 +111,14 @@ public function jdToYmd($julian_day)
}

/**
* Determine the number of months in a year.
* Determine the number of months in a year (if given),
* or the maximum number of months in any year.
*
* @param int|null $year
*
* @return int
*/
public function monthsInYear()
public function monthsInYear($year = null)
{
return 12;
}
Expand Down
7 changes: 5 additions & 2 deletions src/CalendarInterface.php
Expand Up @@ -81,11 +81,14 @@ public function jdStart();
public function jdToYmd($julian_day);

/**
* Determine the number of months in a year.
* Determine the number of months in a year (if given),
* or the maximum number of months in any year.
*
* @param int|null $year
*
* @return int
*/
public function monthsInYear();
public function monthsInYear($year = null);

/**
* Convert a year/month/day to a Julian day number.
Expand Down
7 changes: 5 additions & 2 deletions src/FrenchCalendar.php
Expand Up @@ -119,11 +119,14 @@ public function jdToYmd($julian_day)
}

/**
* Determine the number of months in a year.
* Determine the number of months in a year (if given),
* or the maximum number of months in any year.
*
* @param int|null $year
*
* @return int
*/
public function monthsInYear()
public function monthsInYear($year = null)
{
return 13;
}
Expand Down
11 changes: 9 additions & 2 deletions src/JewishCalendar.php
Expand Up @@ -298,12 +298,19 @@ public function jdToYmd($julian_day)
}

/**
* Determine the number of months in a year.
* Determine the number of months in a year (if given),
* or the maximum number of months in any year.
*
* @param int|null $year
*
* @return int
*/
public function monthsInYear()
public function monthsInYear($year = null)
{
if ($year !== null && !$this->isLeapYear($year)) {
return 12;
}

return 13;
}

Expand Down
7 changes: 5 additions & 2 deletions src/JulianCalendar.php
Expand Up @@ -130,11 +130,14 @@ public function jdToYmd($julian_day)
}

/**
* Determine the number of months in a year.
* Determine the number of months in a year (if given),
* or the maximum number of months in any year.
*
* @param int|null $year
*
* @return int
*/
public function monthsInYear()
public function monthsInYear($year = null)
{
return 12;
}
Expand Down
7 changes: 5 additions & 2 deletions src/PersianCalendar.php
Expand Up @@ -135,11 +135,14 @@ public function jdToYmd($julian_day)
}

/**
* Determine the number of months in a year.
* Determine the number of months in a year (if given),
* or the maximum number of months in any year.
*
* @param int|null $year
*
* @return int
*/
public function monthsInYear()
public function monthsInYear($year = null)
{
return 12;
}
Expand Down
2 changes: 1 addition & 1 deletion test/GregorianCalendarTest.php
Expand Up @@ -258,7 +258,7 @@ public function testJdToYmdReciprocity()
*/
public function testYmdToJdInvalidMonth()
{
$calendar = new ArabicCalendar();
$calendar = new GregorianCalendar();
$calendar->ymdToJd(4, 14, 1);
}
}
29 changes: 14 additions & 15 deletions test/JewishCalendarTest.php
Expand Up @@ -52,7 +52,20 @@ public function testConstants()
$this->assertSame(347998, $this->jewish->jdStart());
$this->assertSame(PHP_INT_MAX, $this->jewish->jdEnd());
$this->assertSame(7, $this->jewish->daysInWeek());
}

/**
* Test the leap year calculations.
*
* @covers \Fisharebest\ExtCalendar\JewishCalendar::monthsInYear
*
* @return void
*/
public function testMonthsInYear()
{
$this->assertSame(13, $this->jewish->monthsInYear());
$this->assertSame(12, $this->jewish->monthsInYear(5767));
$this->assertSame(13, $this->jewish->monthsInYear(5768));
}

/**
Expand Down Expand Up @@ -298,21 +311,7 @@ public function testJdToYmdReciprocity()
}
}

/**
* Test the conversion of a YMD date to JD when the month is not a valid number.
*
* @covers \Fisharebest\ExtCalendar\JewishCalendar::ymdToJd
*
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Month 14 is invalid for this calendar
*/
public function testYmdToJdInvalidMonth()
{
$calendar = new ArabicCalendar();
$calendar->ymdToJd(4, 14, 1);
}

/**
/**
* Test the conversion of numbers into Hebrew numerals.
*
* @large This test can take several seconds to run.
Expand Down
2 changes: 1 addition & 1 deletion test/JulianCalendarTest.php
Expand Up @@ -258,7 +258,7 @@ public function testJdToYmdReciprocity()
*/
public function testYmdToJdInvalidMonth()
{
$calendar = new ArabicCalendar();
$calendar = new JulianCalendar();
$calendar->ymdToJd(4, 14, 1);
}
}
2 changes: 1 addition & 1 deletion test/PersianCalendarTest.php
Expand Up @@ -326,7 +326,7 @@ public function testJdToYmdReciprocity()
*/
public function testYmdToJdInvalidMonth()
{
$calendar = new ArabicCalendar();
$calendar = new PersianCalendar();
$calendar->ymdToJd(4, 14, 1);
}
}

0 comments on commit 7c7d340

Please sign in to comment.