/** * 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()); }
/** * 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); }
public function testYearBoundary() { $startDate = new \DateTime('2015-12-20', new \DateTimeZone('America/New_York')); $result = Yasumi::nextWorkingDay('USA', $startDate, 20); /** * 20 working days between 20th Dec and 20th Jan * 2015-12-20 is a Sunday * 21st - 24th (4 Workdays) * 25th Christmas, 26th-27th Weekend * 28th - 31st (4 Workdays) * 1st Jan New Years, 2nd-3rd Weekend * 4th - 8th (5 Workdays) * 9th-10th Weekend * 11th-15th (5 Workdays) * 16th-17th Weekend, 18th Martin Luther King Day * 19th-20th (2 Workdays) * * @see https://www.timeanddate.com/calendar/?year=2016&country=1 */ $this->assertEquals('2016-01-20', $result->format('Y-m-d')); $startDate = new \DateTime('2016-01-20', new \DateTimeZone('America/New_York')); $result = Yasumi::prevWorkingDay('USA', $startDate, 20); $this->assertEquals('2015-12-18', $result->format('Y-m-d')); }
/** * 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))); }
/** * Creates a new Holiday. * * If a holiday date needs to be defined for a specific timezone, make sure that the date instance (DateTime) has * the correct timezone set. Otherwise the default system timezone is used. * * @param string $shortName The short name (internal name) of this holiday * @param array $names An array containing the name/description of this holiday in various * languages. Overrides global translations * @param DateTime $date A DateTime instance representing the date of the holiday * @param string $displayLocale Locale (i.e. language) in which the holiday information needs to be * displayed in. (Default 'en_US') * @param string $type The type of holiday. Use the following constants: TYPE_NATIONAL, * TYPE_OBSERVANCE, TYPE_SEASON, TYPE_BANK or TYPE_OTHER. By default a * national holiday is considered. * * @throws UnknownLocaleException */ public function __construct($shortName, array $names, $date, $displayLocale = self::DEFAULT_LOCALE, $type = self::TYPE_NATIONAL) { // Validate if short name is not empty if (empty($shortName)) { throw new InvalidArgumentException('Holiday name can not be blank.'); } // Validate if date parameter is instance of DateTime if (!$date instanceof DateTime) { throw new InvalidArgumentException(sprintf('Date "%s" is not a valid DateTime instance.', $date)); } // Load internal locales variable if (!isset(static::$locales)) { static::$locales = Yasumi::getAvailableLocales(); } // Assert display locale input if (!in_array($displayLocale, static::$locales)) { throw new UnknownLocaleException(sprintf('Locale "%s" is not a valid locale.', $displayLocale)); } // Set additional attributes $this->shortName = $shortName; $this->translations = $names; $this->displayLocale = $displayLocale; $this->type = $type; // Construct instance parent::__construct($date->format('Y-m-d'), $date->getTimezone()); }
/** * 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); }
/** * 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); }
/** * 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); }