Skip to content

Commit

Permalink
Add DayOfWeek::isWeekday() and isWeekend()
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed Jun 30, 2021
1 parent 7407a79 commit da6c257
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/DayOfWeek.php
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,22 @@ public function isEqualTo(DayOfWeek $that) : bool
return $this->value === $that->value;
}

/**
* Returns whether this DayOfWeek is Monday to Friday.
*/
public function isWeekday() : bool
{
return $this->value >= self::MONDAY && $this->value <= self::FRIDAY;
}

/**
* Returns whether this DayOfWeek is Saturday or Sunday.
*/
public function isWeekend() : bool
{
return $this->value === self::SATURDAY || $this->value === self::SUNDAY;
}

/**
* Returns the DayOfWeek that is the specified number of days after this one.
*/
Expand Down
42 changes: 42 additions & 0 deletions tests/DayOfWeekTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,48 @@ public function testIsEqualTo(): void
}
}

/**
* @dataProvider providerIsWeekday
*/
public function testIsWeekday(DayOfWeek $dayOfWeek, bool $isWeekday): void
{
$this->assertSame($isWeekday, $dayOfWeek->isWeekday());
}

public function providerIsWeekday(): array
{
return [
[DayOfWeek::monday(), true],
[DayOfWeek::tuesday(), true],
[DayOfWeek::wednesday(), true],
[DayOfWeek::thursday(), true],
[DayOfWeek::friday(), true],
[DayOfWeek::saturday(), false],
[DayOfWeek::sunday(), false],
];
}

/**
* @dataProvider providerIsWeekend
*/
public function testIsWeekend(DayOfWeek $dayOfWeek, bool $isWeekend): void
{
$this->assertSame($isWeekend, $dayOfWeek->isWeekend());
}

public function providerIsWeekend(): array
{
return [
[DayOfWeek::monday(), false],
[DayOfWeek::tuesday(), false],
[DayOfWeek::wednesday(), false],
[DayOfWeek::thursday(), false],
[DayOfWeek::friday(), false],
[DayOfWeek::saturday(), true],
[DayOfWeek::sunday(), true],
];
}

/**
* @dataProvider providerPlus
*
Expand Down

0 comments on commit da6c257

Please sign in to comment.