Skip to content

Commit

Permalink
Fix #28 Test and document getYearHolidays
Browse files Browse the repository at this point in the history
  • Loading branch information
kylekatarnls committed Mar 29, 2019
1 parent 42876fa commit b814dfb
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 26 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,35 @@ holidays common to all states).
Before selecting a region the list of holidays is
empty so `isHoliday` will return `false` for any date.

#### getYearHolidays

Get the holiday dates list for a given year:

```php
Carbon::setHolidaysRegion('us');

foreach (Carbon::getYearHolidays(2020) as $id => $holiday) {
echo $holiday->getHolidayName().': '.$holiday->format('l, F j, Y')."\n";
}

// If Carbon::getYearHolidays() is called without argument, current year is used instead.
```

It will output:

```text
New Year: Wednesday, January 1, 2020
Martin Luther King Jr. Day: Monday, January 20, 2020
Washington’s Birthday: Monday, February 17, 2020
Memorial Day: Monday, May 25, 2020
Independence Day: Monday, July 6, 2020
Labor Day: Monday, September 7, 2020
Columbus Day: Monday, October 12, 2020
Day of the veterans: Wednesday, November 11, 2020
Thanksgiving: Thursday, November 26, 2020
Christmas: Friday, December 25, 2020
```

#### getHolidays

This method allow you to get the holiday list for a
Expand Down
3 changes: 1 addition & 2 deletions src/Cmixin/HolidayNames/en.php
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@
'09-17' => 'National Hero Day',
'03-24' => 'Day of Remembrance for Truth and Justice',
'substitutes-03-24-if-tuesday-then-previous-monday-if-thursday-then-next-friday' => 'Bridge Day',
'veterans-day' => 'Day of the veterans and the fallen in Malvinas War',
'veterans-day' => 'Day of the veterans',
'substitutes-04-02-if-tuesday-then-previous-monday-if-thursday-then-next-friday' => 'Bridge Day',
'substitutes-05-01-if-tuesday-then-previous-monday-if-thursday-then-next-friday' => 'Bridge Day',
'05-25' => 'Day of the First National Government',
Expand Down Expand Up @@ -1017,7 +1017,6 @@
'1st-monday-in-august' => 'August Monday',
'1st-thursday-in-august' => 'August Thursday',
'2nd-saturday-in-october' => 'Translator\'s Day',
'04-02' => 'Day of the veterans and the fallen in Malvinas War',
'3rd-monday-in-august' => 'Anniversary of the death of General José de San Martín',
'10-12-if-tuesday,wednesday-then-previous-monday-if-thursday,friday,saturday,sunday-then-next-monday' => 'Day of Respect for Cultural Diversity',
'4th-monday-in-november' => 'Day of National Sovereignty',
Expand Down
48 changes: 24 additions & 24 deletions src/Cmixin/Holidays/ar-national.php
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?php

return array(
'new-year' => '01-01',
'easter-48' => '= easter -48',
'easter-47' => '= easter -47',
'03-24' => '03-24',
'substitutes-03-24' => '= 03-24 if Tuesday then previous Monday and if Thursday then next Friday',
'easter-3' => '= easter -3',
'easter-2' => '= easter -2',
'04-02' => '04-02',
'substitutes-04-02' => '= 04-02 if Tuesday then previous Monday and if Thursday then next Friday',
'05-01' => '05-01',
'substitutes-05-01' => '= 05-01 if Tuesday then previous Monday and if Thursday then next Friday',
'05-25' => '05-25',
'substitutes-05-25' => '= 05-25 if Tuesday then previous Monday and if Thursday then next Friday',
'06-20' => '06-20',
'substitutes-06-20' => '= 06-20 if Tuesday then previous Monday and if Thursday then next Friday',
'07-09' => '07-09',
'3rd-monday-of-august' => '= third Monday of August',
'10-12' => '= 10-12 if Tuesday,Wednesday then previous Monday and if Thursday,Friday,Saturday,Sunday then next Monday',
'4th-monday-of-november' => '= fourth Monday of November',
'12-08' => '12-08',
'substitutes-12-08' => '= 12-08 if Tuesday then previous Monday and if Thursday then next Friday',
'substitutes-12-24' => '= 12-24 if Tuesday then previous Monday',
'christmas' => '12-25',
'substitutes-12-25' => '= 12-25 if Thursday then next Friday',
'new-year' => '01-01',
'easter-48' => '= easter -48',
'easter-47' => '= easter -47',
'03-24' => '03-24',
'substitutes-03-24' => '= 03-24 if Tuesday then previous Monday and if Thursday then next Friday',
'easter-3' => '= easter -3',
'easter-2' => '= easter -2',
'day-of-the-veterans-and-the-fallen-of-malvinas-war' => '04-02',
'substitutes-04-02' => '= 04-02 if Tuesday then previous Monday and if Thursday then next Friday',
'05-01' => '05-01',
'substitutes-05-01' => '= 05-01 if Tuesday then previous Monday and if Thursday then next Friday',
'05-25' => '05-25',
'substitutes-05-25' => '= 05-25 if Tuesday then previous Monday and if Thursday then next Friday',
'06-20' => '06-20',
'substitutes-06-20' => '= 06-20 if Tuesday then previous Monday and if Thursday then next Friday',
'07-09' => '07-09',
'3rd-monday-of-august' => '= third Monday of August',
'10-12' => '= 10-12 if Tuesday,Wednesday then previous Monday and if Thursday,Friday,Saturday,Sunday then next Monday',
'4th-monday-of-november' => '= fourth Monday of November',
'12-08' => '12-08',
'substitutes-12-08' => '= 12-08 if Tuesday then previous Monday and if Thursday then next Friday',
'substitutes-12-24' => '= 12-24 if Tuesday then previous Monday',
'christmas' => '12-25',
'substitutes-12-25' => '= 12-25 if Thursday then next Friday',
);
24 changes: 24 additions & 0 deletions tests/Cmixin/ListsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,28 @@ public function testNamesInvalidity()

self::assertSame('Christmas', $translations['christmas']);
}

public function testGetYearHolidays()
{
Carbon::setHolidaysRegion('us');

$days = array();

foreach (Carbon::getYearHolidays(2020) as $id => $holiday) {
$days[] = $holiday->getHolidayName().': '.$holiday->format('l, F j, Y');
}

self::assertSame(array(
'New Year: Wednesday, January 1, 2020',
'Martin Luther King Jr. Day: Monday, January 20, 2020',
'Washington’s Birthday: Monday, February 17, 2020',
'Memorial Day: Monday, May 25, 2020',
'Independence Day: Monday, July 6, 2020',
'Labor Day: Monday, September 7, 2020',
'Columbus Day: Monday, October 12, 2020',
'Day of the veterans: Wednesday, November 11, 2020',
'Thanksgiving: Thursday, November 26, 2020',
'Christmas: Friday, December 25, 2020',
), $days);
}
}

0 comments on commit b814dfb

Please sign in to comment.