Skip to content

Commit

Permalink
Add New Years Eve method
Browse files Browse the repository at this point in the history
  • Loading branch information
dansoppelsa committed Jan 27, 2020
1 parent 3a6f0db commit 7971086
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ A handy collection of `Illuminate\Support\Carbon` date helpers
- isVeteransDay
- isAmericanThanksgiving
- isChristmasDay
- isNewYearsEve

### Canadian Dates
- isNewYearsDay
Expand All @@ -31,6 +32,7 @@ A handy collection of `Illuminate\Support\Carbon` date helpers
- isRemembranceDay
- isChristmasDay
- isBoxingDay
- isNewYearsEve


## Installation
Expand Down
4 changes: 4 additions & 0 deletions src/CarbonMacrosServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,5 +196,9 @@ public function register()

return $this->clone()->nthOfMonth(2, static::MONDAY)->day === $this->day;
});

Carbon::macro('isNewYearsEve', function () {
return $this->month === 12 && $this->day === 31;
});
}
}
23 changes: 23 additions & 0 deletions tests/USHolidaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,27 @@ public function provideColumbusDayData()
'2025-10-13' => ['2025-10-13', true],
];
}

/**
* @dataProvider provideNewYearsEveData
*/
public function test_it_knows_new_years_eve($date, $validity)
{
$date = Carbon::parse($date);

$this->assertSame($validity, $date->isNewYearsEve());
}

public function provideNewYearsEveData()
{
return [
'1800-12-31' => ['1800-12-31', true],
'1950-12-31' => ['1950-12-31', true],
'2020-07-04' => ['2020-07-04', false],
'2020-12-30' => ['2020-12-30', false],
'2020-12-31' => ['2020-12-31', true],
'2021-01-01' => ['2021-01-01', false],
'2050-12-31' => ['2050-12-31', true],
];
}
}

0 comments on commit 7971086

Please sign in to comment.