diff --git a/src/Holiday.php b/src/Holiday.php index 2ca7384..c7791eb 100644 --- a/src/Holiday.php +++ b/src/Holiday.php @@ -39,6 +39,27 @@ public function __construct(Repository $config) $this->country = $config->get('yasumi.country'); $this->locale = $config->get('yasumi.locale'); } + + /** + * @param string $country + * @return Holiday + */ + public function country($country) + { + $this->country = $country; + + return $this; + } + + /** + * @param string $locale + * @return Holiday + */ + public function locale($locale){ + $this->locale = $locale; + + return $this; + } /** * @param Carbon $carbon diff --git a/tests/HolidayTest.php b/tests/HolidayTest.php index 909a1a1..ebfa776 100644 --- a/tests/HolidayTest.php +++ b/tests/HolidayTest.php @@ -114,4 +114,29 @@ public function testIsDayBeforeHoliday($country, $locale, $date, $expectedHolida $newYear = Carbon::make($date)->subDay(); $this->assertTrue($holiday->isDayBeforeHoliday($newYear)); } + + /** + * @throws ReflectionException + * @throws MissingTranslationException + */ + public function testCountry() + { + $config = new Repository([ + 'yasumi' => [ + 'country' => 'Japan', + 'locale' => 'ja_JP', + ], + ]); + $spainConstitutionDay = Carbon::make('2020-12-06'); + $holiday = (new Holiday($config))->country('Spain')->locale('es'); + $this->assertEquals('Día de la Constitución', $holiday->get($spainConstitutionDay)); + + $usaIndependenceDay = Carbon::make('2020-07-04'); + $holiday = (new Holiday($config))->country('USA')->locale('en_US'); + $this->assertEquals('Independence Day', $holiday->get($usaIndependenceDay)); + + $holiday = new Holiday($config); + $newYear = Carbon::make('2020-01-01'); + $this->assertEquals('元日', $holiday->get($newYear)); + } } \ No newline at end of file