Skip to content

Commit

Permalink
🔨 Adding new on demand country and language.
Browse files Browse the repository at this point in the history
  • Loading branch information
contactinquid committed Dec 7, 2023
1 parent fd2a7fa commit 7a25ee4
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/Holiday.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions tests/HolidayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

0 comments on commit 7a25ee4

Please sign in to comment.