Skip to content

Commit

Permalink
refactor: make omer check a bit more straightforward
Browse files Browse the repository at this point in the history
  • Loading branch information
tam5 committed Jul 7, 2021
1 parent 591702a commit e5e5c25
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
14 changes: 4 additions & 10 deletions src/Moadim/Omer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,10 @@ trait Omer
*/
public function getOmerCount()
{
if ($this->jewishMonth == 8 && $this->jewishDay >= 16) {
return $this->jewishDay - 15;
}
if ($this->jewishMonth == 9) {
return $this->jewishDay + 15;
}
if ($this->jewishMonth == 10 && $this->jewishDay <= 5) {
return $this->jewishDay + 44;
}
$count = $this->diffInDays(
static::firstDayOfPesach($this->jewishYear)
);

return 0;
return $count > 0 && $count < 50 ? $count : null;
}
}
7 changes: 4 additions & 3 deletions tests/Moadim/OmerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ class OmerTest extends \PHPUnit\Framework\TestCase
/** @test */
public function checks_omer_count()
{
$this->assertEquals(0, Zman::parse('March 28, 2021')->getOmerCount());
$this->assertEquals(1, Zman::parse('March 29, 2021')->getOmerCount());
$this->assertEquals(33, Zman::parse('April 30, 2021')->getOmerCount());
$this->assertEquals(49, Zman::parse('May 16, 2021')->getOmerCount());
$this->assertEquals(0, Zman::parse('May 17, 2021')->getOmerCount());
$this->assertEquals(0, Zman::parse('November 14, 2021')->getOmerCount());

$this->assertNull(Zman::parse('March 28, 2021')->getOmerCount());
$this->assertNull(Zman::parse('May 17, 2021')->getOmerCount());
$this->assertNull(Zman::parse('November 14, 2021')->getOmerCount());
}
}

0 comments on commit e5e5c25

Please sign in to comment.