create() public static method

A new holiday provider instance can be created using this function. You can use one of the providers included already with Yasumi, or your own provider by giving the name of your class in the first parameter. Your provider class needs to implement the 'ProviderInterface' class.
public static create ( string $class, integer $year = null, string $locale = self::DEFAULT_LOCALE ) : AbstractProvider
$class string holiday provider name
$year integer year for which the country provider needs to be created. Year needs to be a valid integer between 1000 and 9999.
$locale string The locale to use. If empty we'll use the default locale (en_US)
return Yasumi\Provider\AbstractProvider An instance of class $class is created and returned
Beispiel #1
0
 /**
  * Tests name of Veterans Day after 1954. Veterans Day was named 'Armistice Day' before 1954.
  */
 public function testVeteransDayNameAfter1954()
 {
     $year = $this->generateRandomYear(1954);
     $holidays = Yasumi::create(self::REGION, $year);
     $holiday = $holidays->getHoliday(self::HOLIDAY);
     $this->assertEquals('Veterans Day', $holiday->getName());
 }
Beispiel #2
0
 /**
  * Tests the holiday before it was adjusted.
  */
 public function testHolidayAfterAdjustment()
 {
     $year = $this->generateRandomYear(self::ADJUSTMENT_YEAR);
     $holidays = Yasumi::create(self::REGION, $year);
     $holiday = $holidays->getHoliday(self::HOLIDAY);
     // Some basic assertions
     $this->assertInstanceOf('Yasumi\\Provider\\' . str_replace('/', '\\', self::REGION), $holidays);
     $this->assertInstanceOf('Yasumi\\Holiday', $holiday);
     $this->assertTrue(isset($holiday));
     // Holiday specific assertions
     $this->assertEquals('Saturday', $holiday->format('l'));
     $this->assertGreaterThanOrEqual(20, $holiday->format('j'));
     $this->assertLessThanOrEqual(26, $holiday->format('j'));
     unset($holiday, $holidays);
 }
 /**
  * Tests that an InvalidArgumentException is thrown in case an invalid holiday provider is given.
  *
  * @expectedException InvalidArgumentException
  */
 public function testWrongDates()
 {
     $year = 2017;
     $timezone = 'America/New_York';
     $holidays = Yasumi::create('USA', $year);
     $holidays->between(new DateTime('12/31/' . $year, new DateTimeZone($timezone)), new DateTime('01/01/' . $year, new DateTimeZone($timezone)));
 }
Beispiel #4
0
 /**
  * Asserts that the expected type is indeed the associated type of the given holiday
  *
  * @param string $provider  the holiday provider (i.e. country/region) for which the holiday need to be tested
  * @param string $shortName string the short name of the holiday to be checked against
  * @param int    $year      holiday calendar year
  * @param string $type      the type to be checked against
  */
 public function assertHolidayType($provider, $shortName, $year, $type)
 {
     $holidays = Yasumi::create($provider, $year);
     $holiday = $holidays->getHoliday($shortName);
     $this->assertInstanceOf('Yasumi\\Provider\\' . str_replace('/', '\\', $provider), $holidays);
     $this->assertInstanceOf('Yasumi\\Holiday', $holiday);
     $this->assertTrue(isset($holiday));
     $this->assertEquals($type, $holiday->getType());
     unset($holiday, $holidays);
 }
 /**
  * Tests other type of Holidays for holidays that are not other type of holidays
  */
 public function testOtherHolidaysFilterNotOtherHolidays()
 {
     $holidays = Yasumi::create('Netherlands', 2015);
     $otherHolidays = iterator_to_array(new OtherHolidaysFilter($holidays->getIterator()));
     $this->assertArrayNotHasKey('newYearsDay', $otherHolidays);
     $this->assertArrayNotHasKey('pentecost', $otherHolidays);
 }
Beispiel #6
0
 /**
  * Tests that the IsWorkingDay function returns a boolean true for a date that is defined as a holiday or falls in
  * the weekend.
  */
 public function testIsNotWorkingDay()
 {
     $year = 2016;
     $isNotWorkingDay = Yasumi::create('Japan', $year)->isWorkingDay(new DateTime($year . '-01-11'));
     $this->assertInternalType('bool', $isNotWorkingDay);
     $this->assertFalse($isNotWorkingDay);
     unset($isWorkingDay);
 }
Beispiel #7
0
 /**
  * Determines the date of the given holiday for another year.
  *
  * @param int    $year      the year to get the holiday date for
  * @param string $shortName the name of the holiday for which the date needs to be fetched
  *
  * @throws InvalidArgumentException when the given name is blank or empty.
  *
  * @return Holiday a Holiday instance for the given holiday and year
  */
 private function anotherTime($year, $shortName)
 {
     $this->isHolidayNameNotEmpty($shortName);
     // Validate if short name is not empty
     // Get calling class name
     $hReflectionClass = new \ReflectionClass(get_class($this));
     return Yasumi::create($hReflectionClass->getShortName(), $year, $this->locale)->getHoliday($shortName);
 }