@@ -16,16 +16,16 @@  | 
                                                    ||
| 16 | 16 | |
| 17 | 17 | class EasterFactory implements ItemFromDomElementCreator  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | - public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 20 | -	{ | 
                                                        |
| 21 | -		if ($element->nodeName !== 'easter') { | 
                                                        |
| 22 | - return null;  | 
                                                        |
| 23 | - }  | 
                                                        |
| 19 | + public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 20 | +    { | 
                                                        |
| 21 | +        if ($element->nodeName !== 'easter') { | 
                                                        |
| 22 | + return null;  | 
                                                        |
| 23 | + }  | 
                                                        |
| 24 | 24 | |
| 25 | - return new Easter(  | 
                                                        |
| 26 | - $element->textContent,  | 
                                                        |
| 27 | -			$element->getAttribute('free') === "true", | 
                                                        |
| 28 | -			(int) $element->getAttribute('offset') | 
                                                        |
| 29 | - );  | 
                                                        |
| 30 | - }  | 
                                                        |
| 25 | + return new Easter(  | 
                                                        |
| 26 | + $element->textContent,  | 
                                                        |
| 27 | +            $element->getAttribute('free') === "true", | 
                                                        |
| 28 | +            (int) $element->getAttribute('offset') | 
                                                        |
| 29 | + );  | 
                                                        |
| 30 | + }  | 
                                                        |
| 31 | 31 | }  | 
                                                        
@@ -18,24 +18,24 @@  | 
                                                    ||
| 18 | 18 | |
| 19 | 19 | class DateFollowupFactory implements ItemFromDomElementCreator  | 
                                                        
| 20 | 20 |  { | 
                                                        
| 21 | - public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 22 | -	{ | 
                                                        |
| 23 | -		if ($element->nodeName !== 'dateFollowUp') { | 
                                                        |
| 24 | - return null;  | 
                                                        |
| 25 | - }  | 
                                                        |
| 21 | + public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 22 | +    { | 
                                                        |
| 23 | +        if ($element->nodeName !== 'dateFollowUp') { | 
                                                        |
| 24 | + return null;  | 
                                                        |
| 25 | + }  | 
                                                        |
| 26 | 26 | |
| 27 | - $day = CalendarDayFactory::createCalendarDay(  | 
                                                        |
| 28 | -			(int) $element->getAttribute('day'), | 
                                                        |
| 29 | -			(int) $element->getAttribute('month'), | 
                                                        |
| 30 | -			($element->hasAttribute('calendar') ? $element->getAttribute('calendar') : 'gregorian') | 
                                                        |
| 31 | - );  | 
                                                        |
| 27 | + $day = CalendarDayFactory::createCalendarDay(  | 
                                                        |
| 28 | +            (int) $element->getAttribute('day'), | 
                                                        |
| 29 | +            (int) $element->getAttribute('month'), | 
                                                        |
| 30 | +            ($element->hasAttribute('calendar') ? $element->getAttribute('calendar') : 'gregorian') | 
                                                        |
| 31 | + );  | 
                                                        |
| 32 | 32 | |
| 33 | - return new DateFollowUp(  | 
                                                        |
| 34 | - $element->textContent,  | 
                                                        |
| 35 | -			$element->getAttribute('free') === "true", | 
                                                        |
| 36 | - $day,  | 
                                                        |
| 37 | -			$element->getAttribute('followup'), | 
                                                        |
| 38 | -			($element->hasAttribute('replaced') ? explode(' ', $element->getAttribute('replaced')) : []) | 
                                                        |
| 39 | - );  | 
                                                        |
| 40 | - }  | 
                                                        |
| 33 | + return new DateFollowUp(  | 
                                                        |
| 34 | + $element->textContent,  | 
                                                        |
| 35 | +            $element->getAttribute('free') === "true", | 
                                                        |
| 36 | + $day,  | 
                                                        |
| 37 | +            $element->getAttribute('followup'), | 
                                                        |
| 38 | +            ($element->hasAttribute('replaced') ? explode(' ', $element->getAttribute('replaced')) : []) | 
                                                        |
| 39 | + );  | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | 41 | }  | 
                                                        
@@ -15,5 +15,5 @@  | 
                                                    ||
| 15 | 15 | |
| 16 | 16 | interface ItemFromDomElementCreator  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | - public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface;  | 
                                                        |
| 18 | + public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface;  | 
                                                        |
| 19 | 19 | }  | 
                                                        
@@ -16,18 +16,18 @@  | 
                                                    ||
| 16 | 16 | |
| 17 | 17 | class RelativeFactory implements ItemFromDomElementCreator  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | - public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 20 | -	{ | 
                                                        |
| 21 | -		if ($element->nodeName !== 'relative') { | 
                                                        |
| 22 | - return null;  | 
                                                        |
| 23 | - }  | 
                                                        |
| 19 | + public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 20 | +    { | 
                                                        |
| 21 | +        if ($element->nodeName !== 'relative') { | 
                                                        |
| 22 | + return null;  | 
                                                        |
| 23 | + }  | 
                                                        |
| 24 | 24 | |
| 25 | - return new Relative(  | 
                                                        |
| 26 | - $element->textContent,  | 
                                                        |
| 27 | -			$element->getAttribute('free') === "true", | 
                                                        |
| 28 | -			(int) $element->getAttribute('day'), | 
                                                        |
| 29 | -			(int) $element->getAttribute('month'), | 
                                                        |
| 30 | -			$element->getAttribute('relation') | 
                                                        |
| 31 | - );  | 
                                                        |
| 32 | - }  | 
                                                        |
| 25 | + return new Relative(  | 
                                                        |
| 26 | + $element->textContent,  | 
                                                        |
| 27 | +            $element->getAttribute('free') === "true", | 
                                                        |
| 28 | +            (int) $element->getAttribute('day'), | 
                                                        |
| 29 | +            (int) $element->getAttribute('month'), | 
                                                        |
| 30 | +            $element->getAttribute('relation') | 
                                                        |
| 31 | + );  | 
                                                        |
| 32 | + }  | 
                                                        |
| 33 | 33 | }  | 
                                                        
@@ -15,5 +15,5 @@  | 
                                                    ||
| 15 | 15 | |
| 16 | 16 | interface DecorateFromDomElement  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | - public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface;  | 
                                                        |
| 18 | + public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface;  | 
                                                        |
| 19 | 19 | }  | 
                                                        
@@ -61,7 +61,7 @@  | 
                                                    ||
| 61 | 61 | return new SwapRule(  | 
                                                        
| 62 | 62 | $direction,  | 
                                                        
| 63 | 63 | GregorianWeekday::fromString($to),  | 
                                                        
| 64 | -			...array_map(function ($item) { | 
                                                        |
| 64 | +			...array_map(function($item) { | 
                                                        |
| 65 | 65 | return GregorianWeekday::fromString($item);  | 
                                                        
| 66 | 66 |  			}, explode(' ', $when)) | 
                                                        
| 67 | 67 | );  | 
                                                        
@@ -22,57 +22,57 @@  | 
                                                    ||
| 22 | 22 | |
| 23 | 23 | final class SwapDecoratorFactory implements DecorateFromDomElement  | 
                                                        
| 24 | 24 |  { | 
                                                        
| 25 | - public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface  | 
                                                        |
| 26 | -	{ | 
                                                        |
| 27 | - $rules = $this->getRulesFromDomElement($domElement);  | 
                                                        |
| 25 | + public function decorate(HolidayIteratorItemInterface $element, DOMElement $domElement): HolidayIteratorItemInterface  | 
                                                        |
| 26 | +    { | 
                                                        |
| 27 | + $rules = $this->getRulesFromDomElement($domElement);  | 
                                                        |
| 28 | 28 | |
| 29 | -		if ($rules === []) { | 
                                                        |
| 30 | - return $element;  | 
                                                        |
| 31 | - }  | 
                                                        |
| 29 | +        if ($rules === []) { | 
                                                        |
| 30 | + return $element;  | 
                                                        |
| 31 | + }  | 
                                                        |
| 32 | 32 | |
| 33 | - $day = CalendarDayFactory::createCalendarDay(  | 
                                                        |
| 34 | -			(int) $domElement->getAttribute('day'), | 
                                                        |
| 35 | -			(int) $domElement->getAttribute('month'), | 
                                                        |
| 36 | -			($domElement->hasAttribute('calendar') ? $domElement->getAttribute('calendar') : 'gregorian') | 
                                                        |
| 37 | - );  | 
                                                        |
| 33 | + $day = CalendarDayFactory::createCalendarDay(  | 
                                                        |
| 34 | +            (int) $domElement->getAttribute('day'), | 
                                                        |
| 35 | +            (int) $domElement->getAttribute('month'), | 
                                                        |
| 36 | +            ($domElement->hasAttribute('calendar') ? $domElement->getAttribute('calendar') : 'gregorian') | 
                                                        |
| 37 | + );  | 
                                                        |
| 38 | 38 | |
| 39 | -		if ($domElement->hasAttribute('year')) { | 
                                                        |
| 40 | -			$day->setYear((int) $domElement->getAttribute('year')); | 
                                                        |
| 41 | - }  | 
                                                        |
| 39 | +        if ($domElement->hasAttribute('year')) { | 
                                                        |
| 40 | +            $day->setYear((int) $domElement->getAttribute('year')); | 
                                                        |
| 41 | + }  | 
                                                        |
| 42 | 42 | |
| 43 | - return new SwapDecorator($element, $day, ...$rules);  | 
                                                        |
| 44 | - }  | 
                                                        |
| 43 | + return new SwapDecorator($element, $day, ...$rules);  | 
                                                        |
| 44 | + }  | 
                                                        |
| 45 | 45 | |
| 46 | - /**  | 
                                                        |
| 47 | - * @return SwapRule[]  | 
                                                        |
| 48 | - */  | 
                                                        |
| 49 | - private function getRulesFromDomElement(DOMElement $domElement): array  | 
                                                        |
| 50 | -	{ | 
                                                        |
| 51 | - $attributes = [  | 
                                                        |
| 52 | - 'forward' => SwapDirection::forward(),  | 
                                                        |
| 53 | - 'alternateforward' => SwapDirection::forward(),  | 
                                                        |
| 54 | - 'rewind' => SwapDirection::rewind(),  | 
                                                        |
| 55 | - 'alternaterewind' => SwapDirection::rewind(),  | 
                                                        |
| 56 | - ];  | 
                                                        |
| 46 | + /**  | 
                                                        |
| 47 | + * @return SwapRule[]  | 
                                                        |
| 48 | + */  | 
                                                        |
| 49 | + private function getRulesFromDomElement(DOMElement $domElement): array  | 
                                                        |
| 50 | +    { | 
                                                        |
| 51 | + $attributes = [  | 
                                                        |
| 52 | + 'forward' => SwapDirection::forward(),  | 
                                                        |
| 53 | + 'alternateforward' => SwapDirection::forward(),  | 
                                                        |
| 54 | + 'rewind' => SwapDirection::rewind(),  | 
                                                        |
| 55 | + 'alternaterewind' => SwapDirection::rewind(),  | 
                                                        |
| 56 | + ];  | 
                                                        |
| 57 | 57 | |
| 58 | - $rules = [];  | 
                                                        |
| 59 | -		foreach ($attributes as $attribute => $direction) { | 
                                                        |
| 60 | -			if ($domElement->hasAttribute($attribute . 'to') && $domElement->hasAttribute($attribute . 'when')) { | 
                                                        |
| 61 | - $rules[] = $this->createRuleFrom($domElement->getAttribute($attribute . 'to'), $domElement->getAttribute($attribute . 'when'), $direction);  | 
                                                        |
| 62 | - }  | 
                                                        |
| 63 | - }  | 
                                                        |
| 58 | + $rules = [];  | 
                                                        |
| 59 | +        foreach ($attributes as $attribute => $direction) { | 
                                                        |
| 60 | +            if ($domElement->hasAttribute($attribute . 'to') && $domElement->hasAttribute($attribute . 'when')) { | 
                                                        |
| 61 | + $rules[] = $this->createRuleFrom($domElement->getAttribute($attribute . 'to'), $domElement->getAttribute($attribute . 'when'), $direction);  | 
                                                        |
| 62 | + }  | 
                                                        |
| 63 | + }  | 
                                                        |
| 64 | 64 | |
| 65 | - return $rules;  | 
                                                        |
| 66 | - }  | 
                                                        |
| 65 | + return $rules;  | 
                                                        |
| 66 | + }  | 
                                                        |
| 67 | 67 | |
| 68 | - private function createRuleFrom(string $to, string $when, SwapDirection $direction): SwapRule  | 
                                                        |
| 69 | -	{ | 
                                                        |
| 70 | - return new SwapRule(  | 
                                                        |
| 71 | - $direction,  | 
                                                        |
| 72 | - GregorianWeekday::fromString($to),  | 
                                                        |
| 73 | -			...array_map(function ($item) { | 
                                                        |
| 74 | - return GregorianWeekday::fromString($item);  | 
                                                        |
| 75 | -			}, explode(' ', $when)) | 
                                                        |
| 76 | - );  | 
                                                        |
| 77 | - }  | 
                                                        |
| 68 | + private function createRuleFrom(string $to, string $when, SwapDirection $direction): SwapRule  | 
                                                        |
| 69 | +    { | 
                                                        |
| 70 | + return new SwapRule(  | 
                                                        |
| 71 | + $direction,  | 
                                                        |
| 72 | + GregorianWeekday::fromString($to),  | 
                                                        |
| 73 | +            ...array_map(function ($item) { | 
                                                        |
| 74 | + return GregorianWeekday::fromString($item);  | 
                                                        |
| 75 | +            }, explode(' ', $when)) | 
                                                        |
| 76 | + );  | 
                                                        |
| 77 | + }  | 
                                                        |
| 78 | 78 | }  | 
                                                        
@@ -12,35 +12,35 @@  | 
                                                    ||
| 12 | 12 | |
| 13 | 13 | class SwapRule  | 
                                                        
| 14 | 14 |  { | 
                                                        
| 15 | - private $swapDirection;  | 
                                                        |
| 16 | -  | 
                                                        |
| 17 | - private $swapToDay;  | 
                                                        |
| 18 | -  | 
                                                        |
| 19 | - /** @var GregorianWeekday[] */  | 
                                                        |
| 20 | - private $swapWhenDay;  | 
                                                        |
| 21 | -  | 
                                                        |
| 22 | - /**  | 
                                                        |
| 23 | - * @param GregorianWeekday[] $swapWhenGregorianDay  | 
                                                        |
| 24 | - */  | 
                                                        |
| 25 | - public function __construct(SwapDirection $direction, GregorianWeekday $swapToGregorianDay, GregorianWeekday ...$swapWhenGregorianDay)  | 
                                                        |
| 26 | -	{ | 
                                                        |
| 27 | - $this->swapDirection = $direction;  | 
                                                        |
| 28 | - $this->swapToDay = $swapToGregorianDay;  | 
                                                        |
| 29 | - $this->swapWhenDay = $swapWhenGregorianDay;  | 
                                                        |
| 30 | - }  | 
                                                        |
| 31 | -  | 
                                                        |
| 32 | - public function getDirection(): SwapDirection  | 
                                                        |
| 33 | -	{ | 
                                                        |
| 34 | - return $this->swapDirection;  | 
                                                        |
| 35 | - }  | 
                                                        |
| 36 | -  | 
                                                        |
| 37 | - public function getSwapToDay(): GregorianWeekday  | 
                                                        |
| 38 | -	{ | 
                                                        |
| 39 | - return $this->swapToDay;  | 
                                                        |
| 40 | - }  | 
                                                        |
| 41 | -  | 
                                                        |
| 42 | - public function getSwapWhenDays(): array  | 
                                                        |
| 43 | -	{ | 
                                                        |
| 44 | - return $this->swapWhenDay;  | 
                                                        |
| 45 | - }  | 
                                                        |
| 15 | + private $swapDirection;  | 
                                                        |
| 16 | +  | 
                                                        |
| 17 | + private $swapToDay;  | 
                                                        |
| 18 | +  | 
                                                        |
| 19 | + /** @var GregorianWeekday[] */  | 
                                                        |
| 20 | + private $swapWhenDay;  | 
                                                        |
| 21 | +  | 
                                                        |
| 22 | + /**  | 
                                                        |
| 23 | + * @param GregorianWeekday[] $swapWhenGregorianDay  | 
                                                        |
| 24 | + */  | 
                                                        |
| 25 | + public function __construct(SwapDirection $direction, GregorianWeekday $swapToGregorianDay, GregorianWeekday ...$swapWhenGregorianDay)  | 
                                                        |
| 26 | +    { | 
                                                        |
| 27 | + $this->swapDirection = $direction;  | 
                                                        |
| 28 | + $this->swapToDay = $swapToGregorianDay;  | 
                                                        |
| 29 | + $this->swapWhenDay = $swapWhenGregorianDay;  | 
                                                        |
| 30 | + }  | 
                                                        |
| 31 | +  | 
                                                        |
| 32 | + public function getDirection(): SwapDirection  | 
                                                        |
| 33 | +    { | 
                                                        |
| 34 | + return $this->swapDirection;  | 
                                                        |
| 35 | + }  | 
                                                        |
| 36 | +  | 
                                                        |
| 37 | + public function getSwapToDay(): GregorianWeekday  | 
                                                        |
| 38 | +    { | 
                                                        |
| 39 | + return $this->swapToDay;  | 
                                                        |
| 40 | + }  | 
                                                        |
| 41 | +  | 
                                                        |
| 42 | + public function getSwapWhenDays(): array  | 
                                                        |
| 43 | +    { | 
                                                        |
| 44 | + return $this->swapWhenDay;  | 
                                                        |
| 45 | + }  | 
                                                        |
| 46 | 46 | }  | 
                                                        
@@ -15,131 +15,131 @@  | 
                                                    ||
| 15 | 15 | |
| 16 | 16 | class CalendarDay  | 
                                                        
| 17 | 17 |  { | 
                                                        
| 18 | - /** @var int */  | 
                                                        |
| 19 | - private $day;  | 
                                                        |
| 20 | -  | 
                                                        |
| 21 | - /** @var int */  | 
                                                        |
| 22 | - private $month;  | 
                                                        |
| 23 | -  | 
                                                        |
| 24 | - /** @var int|null */  | 
                                                        |
| 25 | - private $year = null;  | 
                                                        |
| 26 | -  | 
                                                        |
| 27 | - /** @var IntlCalendar */  | 
                                                        |
| 28 | - private $calendar;  | 
                                                        |
| 29 | -  | 
                                                        |
| 30 | - public function __construct(int $day, int $month, IntlCalendar $calendar)  | 
                                                        |
| 31 | -	{ | 
                                                        |
| 32 | - $this->day = $day;  | 
                                                        |
| 33 | - $this->month = $month;  | 
                                                        |
| 34 | - $this->calendar = $calendar;  | 
                                                        |
| 35 | - $this->calendar->set(IntlCalendar::FIELD_DAY_OF_MONTH, $day);  | 
                                                        |
| 36 | - $this->calendar->set(IntlCalendar::FIELD_MONTH, $month - 1);  | 
                                                        |
| 37 | - $this->calendar->set(IntlCalendar::FIELD_HOUR_OF_DAY, 12);  | 
                                                        |
| 38 | - $this->calendar->set(IntlCalendar::FIELD_MINUTE, 0);  | 
                                                        |
| 39 | - $this->calendar->set(IntlCalendar::FIELD_SECOND, 0);  | 
                                                        |
| 40 | - $this->calendar->set(IntlCalendar::FIELD_MILLISECOND, 0);  | 
                                                        |
| 41 | - }  | 
                                                        |
| 42 | -  | 
                                                        |
| 43 | - public function setYear(int $year): void  | 
                                                        |
| 44 | -	{ | 
                                                        |
| 45 | - $this->year = $year;  | 
                                                        |
| 46 | - $this->calendar->set(IntlCalendar::FIELD_YEAR, $year);  | 
                                                        |
| 47 | - }  | 
                                                        |
| 48 | -  | 
                                                        |
| 49 | - public function setGregorianYear(int $year): void  | 
                                                        |
| 50 | -	{ | 
                                                        |
| 51 | -		$calendarYear = (int) $this->calendar->toDateTime()->format('Y'); | 
                                                        |
| 52 | -  | 
                                                        |
| 53 | - $diff = $year - $calendarYear;  | 
                                                        |
| 54 | - $realYear = $this->calendar->get(IntlCalendar::FIELD_YEAR);  | 
                                                        |
| 55 | -  | 
                                                        |
| 56 | - $this->year = $realYear + $diff;  | 
                                                        |
| 57 | - $this->calendar->add(IntlCalendar::FIELD_YEAR, $diff);  | 
                                                        |
| 58 | - }  | 
                                                        |
| 59 | -  | 
                                                        |
| 60 | - public function isSameDay(DateTimeInterface $dateTime): bool  | 
                                                        |
| 61 | -	{ | 
                                                        |
| 62 | - $cal = clone $this->calendar;  | 
                                                        |
| 63 | - $cal->setTime($dateTime->getTimestamp() * 1000);  | 
                                                        |
| 64 | -  | 
                                                        |
| 65 | - if (null !== $this->year &&  | 
                                                        |
| 66 | - $cal->get(IntlCalendar::FIELD_YEAR) !== $this->calendar->get(IntlCalendar::FIELD_YEAR)  | 
                                                        |
| 67 | -		) { | 
                                                        |
| 68 | - return false;  | 
                                                        |
| 69 | - }  | 
                                                        |
| 70 | -  | 
                                                        |
| 71 | -		if ($cal->get(IntlCalendar::FIELD_MONTH) !== $this->calendar->get(IntlCalendar::FIELD_MONTH)) { | 
                                                        |
| 72 | - return false;  | 
                                                        |
| 73 | - }  | 
                                                        |
| 74 | -  | 
                                                        |
| 75 | - return $cal->get(IntlCalendar::FIELD_DAY_OF_MONTH) === $this->calendar->get(IntlCalendar::FIELD_DAY_OF_MONTH);  | 
                                                        |
| 76 | - }  | 
                                                        |
| 77 | -  | 
                                                        |
| 78 | - public function getCalendar(): IntlCalendar  | 
                                                        |
| 79 | -	{ | 
                                                        |
| 80 | - return clone $this->calendar;  | 
                                                        |
| 81 | - }  | 
                                                        |
| 82 | -  | 
                                                        |
| 83 | - public function hasYearSet(): bool  | 
                                                        |
| 84 | -	{ | 
                                                        |
| 85 | - return null !== $this->year;  | 
                                                        |
| 86 | - }  | 
                                                        |
| 87 | -  | 
                                                        |
| 88 | - public function isFollowUpDay(DateTimeInterface $dateTime, string $followUpDay): bool  | 
                                                        |
| 89 | -	{ | 
                                                        |
| 90 | - return $this->isModifiedDate($dateTime, $followUpDay, 'next');  | 
                                                        |
| 91 | - }  | 
                                                        |
| 92 | -  | 
                                                        |
| 93 | - private function isModifiedDate(DateTimeInterface $dateTime, string $modifiedDay, string $direction): bool  | 
                                                        |
| 94 | -	{ | 
                                                        |
| 95 | - $cal = clone $this->calendar;  | 
                                                        |
| 96 | -		$cal = self::setGregorianYearForDate((int) $dateTime->format('Y'), $cal); | 
                                                        |
| 97 | - $day = $cal->toDateTime();  | 
                                                        |
| 98 | - $day->modify($direction . ' ' . $modifiedDay);  | 
                                                        |
| 99 | - $cal->setTime($day->getTimestamp() * 1000);  | 
                                                        |
| 100 | - $cal2 = clone $this->calendar;  | 
                                                        |
| 101 | - $cal2->setTime($dateTime->getTimestamp() * 1000);  | 
                                                        |
| 102 | -  | 
                                                        |
| 103 | -		if (null !== $this->year && $cal->get(IntlCalendar::FIELD_YEAR) !== $cal2->get(IntlCalendar::FIELD_YEAR)) { | 
                                                        |
| 104 | - return false;  | 
                                                        |
| 105 | - }  | 
                                                        |
| 106 | -  | 
                                                        |
| 107 | -		if ($cal->get(IntlCalendar::FIELD_MONTH) !== $cal2->get(IntlCalendar::FIELD_MONTH)) { | 
                                                        |
| 108 | - return false;  | 
                                                        |
| 109 | - }  | 
                                                        |
| 110 | -  | 
                                                        |
| 111 | - return $cal->get(IntlCalendar::FIELD_DAY_OF_MONTH) === $cal2->get(IntlCalendar::FIELD_DAY_OF_MONTH);  | 
                                                        |
| 112 | - }  | 
                                                        |
| 113 | -  | 
                                                        |
| 114 | - public static function setGregorianYearForDate(int $year, IntlCalendar $calendar): IntlCalendar  | 
                                                        |
| 115 | -	{ | 
                                                        |
| 116 | - $datetime = $calendar->toDateTime();  | 
                                                        |
| 117 | -		$yearDiff = $year - (int) $datetime->format('Y'); | 
                                                        |
| 118 | -  | 
                                                        |
| 119 | - $calendar->set(IntlCalendar::FIELD_YEAR, $calendar->get(IntlCalendar::FIELD_YEAR) + $yearDiff);  | 
                                                        |
| 120 | -		if ($calendar->toDateTime()->format('Y') < $year) { | 
                                                        |
| 121 | - $calendar->set(IntlCalendar::FIELD_YEAR, $calendar->get(IntlCalendar::FIELD_YEAR) + 1);  | 
                                                        |
| 122 | - }  | 
                                                        |
| 123 | -		if ($calendar->toDateTime()->format('Y') > $year) { | 
                                                        |
| 124 | - $calendar->set(IntlCalendar::FIELD_YEAR, $calendar->get(IntlCalendar::FIELD_YEAR) - 1);  | 
                                                        |
| 125 | - }  | 
                                                        |
| 126 | -  | 
                                                        |
| 127 | - return $calendar;  | 
                                                        |
| 128 | - }  | 
                                                        |
| 129 | -  | 
                                                        |
| 130 | - public function getWeekdayForGregorianYear(int $year): int  | 
                                                        |
| 131 | -	{ | 
                                                        |
| 132 | - $cal = $this->getDayForGregorianYear($year);  | 
                                                        |
| 133 | -  | 
                                                        |
| 134 | - return $cal->get(IntlCalendar::FIELD_DAY_OF_WEEK);  | 
                                                        |
| 135 | - }  | 
                                                        |
| 136 | -  | 
                                                        |
| 137 | - private function getDayForGregorianYear(int $gregorianYear): IntlCalendar  | 
                                                        |
| 138 | -	{ | 
                                                        |
| 139 | - $cal = clone $this->calendar;  | 
                                                        |
| 140 | - $cal->set(IntlCalendar::FIELD_MONTH, $this->month - 1);  | 
                                                        |
| 141 | - $cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, $this->day);  | 
                                                        |
| 142 | -  | 
                                                        |
| 143 | - return self::setGregorianYearForDate($gregorianYear, $cal);  | 
                                                        |
| 144 | - }  | 
                                                        |
| 18 | + /** @var int */  | 
                                                        |
| 19 | + private $day;  | 
                                                        |
| 20 | +  | 
                                                        |
| 21 | + /** @var int */  | 
                                                        |
| 22 | + private $month;  | 
                                                        |
| 23 | +  | 
                                                        |
| 24 | + /** @var int|null */  | 
                                                        |
| 25 | + private $year = null;  | 
                                                        |
| 26 | +  | 
                                                        |
| 27 | + /** @var IntlCalendar */  | 
                                                        |
| 28 | + private $calendar;  | 
                                                        |
| 29 | +  | 
                                                        |
| 30 | + public function __construct(int $day, int $month, IntlCalendar $calendar)  | 
                                                        |
| 31 | +    { | 
                                                        |
| 32 | + $this->day = $day;  | 
                                                        |
| 33 | + $this->month = $month;  | 
                                                        |
| 34 | + $this->calendar = $calendar;  | 
                                                        |
| 35 | + $this->calendar->set(IntlCalendar::FIELD_DAY_OF_MONTH, $day);  | 
                                                        |
| 36 | + $this->calendar->set(IntlCalendar::FIELD_MONTH, $month - 1);  | 
                                                        |
| 37 | + $this->calendar->set(IntlCalendar::FIELD_HOUR_OF_DAY, 12);  | 
                                                        |
| 38 | + $this->calendar->set(IntlCalendar::FIELD_MINUTE, 0);  | 
                                                        |
| 39 | + $this->calendar->set(IntlCalendar::FIELD_SECOND, 0);  | 
                                                        |
| 40 | + $this->calendar->set(IntlCalendar::FIELD_MILLISECOND, 0);  | 
                                                        |
| 41 | + }  | 
                                                        |
| 42 | +  | 
                                                        |
| 43 | + public function setYear(int $year): void  | 
                                                        |
| 44 | +    { | 
                                                        |
| 45 | + $this->year = $year;  | 
                                                        |
| 46 | + $this->calendar->set(IntlCalendar::FIELD_YEAR, $year);  | 
                                                        |
| 47 | + }  | 
                                                        |
| 48 | +  | 
                                                        |
| 49 | + public function setGregorianYear(int $year): void  | 
                                                        |
| 50 | +    { | 
                                                        |
| 51 | +        $calendarYear = (int) $this->calendar->toDateTime()->format('Y'); | 
                                                        |
| 52 | +  | 
                                                        |
| 53 | + $diff = $year - $calendarYear;  | 
                                                        |
| 54 | + $realYear = $this->calendar->get(IntlCalendar::FIELD_YEAR);  | 
                                                        |
| 55 | +  | 
                                                        |
| 56 | + $this->year = $realYear + $diff;  | 
                                                        |
| 57 | + $this->calendar->add(IntlCalendar::FIELD_YEAR, $diff);  | 
                                                        |
| 58 | + }  | 
                                                        |
| 59 | +  | 
                                                        |
| 60 | + public function isSameDay(DateTimeInterface $dateTime): bool  | 
                                                        |
| 61 | +    { | 
                                                        |
| 62 | + $cal = clone $this->calendar;  | 
                                                        |
| 63 | + $cal->setTime($dateTime->getTimestamp() * 1000);  | 
                                                        |
| 64 | +  | 
                                                        |
| 65 | + if (null !== $this->year &&  | 
                                                        |
| 66 | + $cal->get(IntlCalendar::FIELD_YEAR) !== $this->calendar->get(IntlCalendar::FIELD_YEAR)  | 
                                                        |
| 67 | +        ) { | 
                                                        |
| 68 | + return false;  | 
                                                        |
| 69 | + }  | 
                                                        |
| 70 | +  | 
                                                        |
| 71 | +        if ($cal->get(IntlCalendar::FIELD_MONTH) !== $this->calendar->get(IntlCalendar::FIELD_MONTH)) { | 
                                                        |
| 72 | + return false;  | 
                                                        |
| 73 | + }  | 
                                                        |
| 74 | +  | 
                                                        |
| 75 | + return $cal->get(IntlCalendar::FIELD_DAY_OF_MONTH) === $this->calendar->get(IntlCalendar::FIELD_DAY_OF_MONTH);  | 
                                                        |
| 76 | + }  | 
                                                        |
| 77 | +  | 
                                                        |
| 78 | + public function getCalendar(): IntlCalendar  | 
                                                        |
| 79 | +    { | 
                                                        |
| 80 | + return clone $this->calendar;  | 
                                                        |
| 81 | + }  | 
                                                        |
| 82 | +  | 
                                                        |
| 83 | + public function hasYearSet(): bool  | 
                                                        |
| 84 | +    { | 
                                                        |
| 85 | + return null !== $this->year;  | 
                                                        |
| 86 | + }  | 
                                                        |
| 87 | +  | 
                                                        |
| 88 | + public function isFollowUpDay(DateTimeInterface $dateTime, string $followUpDay): bool  | 
                                                        |
| 89 | +    { | 
                                                        |
| 90 | + return $this->isModifiedDate($dateTime, $followUpDay, 'next');  | 
                                                        |
| 91 | + }  | 
                                                        |
| 92 | +  | 
                                                        |
| 93 | + private function isModifiedDate(DateTimeInterface $dateTime, string $modifiedDay, string $direction): bool  | 
                                                        |
| 94 | +    { | 
                                                        |
| 95 | + $cal = clone $this->calendar;  | 
                                                        |
| 96 | +        $cal = self::setGregorianYearForDate((int) $dateTime->format('Y'), $cal); | 
                                                        |
| 97 | + $day = $cal->toDateTime();  | 
                                                        |
| 98 | + $day->modify($direction . ' ' . $modifiedDay);  | 
                                                        |
| 99 | + $cal->setTime($day->getTimestamp() * 1000);  | 
                                                        |
| 100 | + $cal2 = clone $this->calendar;  | 
                                                        |
| 101 | + $cal2->setTime($dateTime->getTimestamp() * 1000);  | 
                                                        |
| 102 | +  | 
                                                        |
| 103 | +        if (null !== $this->year && $cal->get(IntlCalendar::FIELD_YEAR) !== $cal2->get(IntlCalendar::FIELD_YEAR)) { | 
                                                        |
| 104 | + return false;  | 
                                                        |
| 105 | + }  | 
                                                        |
| 106 | +  | 
                                                        |
| 107 | +        if ($cal->get(IntlCalendar::FIELD_MONTH) !== $cal2->get(IntlCalendar::FIELD_MONTH)) { | 
                                                        |
| 108 | + return false;  | 
                                                        |
| 109 | + }  | 
                                                        |
| 110 | +  | 
                                                        |
| 111 | + return $cal->get(IntlCalendar::FIELD_DAY_OF_MONTH) === $cal2->get(IntlCalendar::FIELD_DAY_OF_MONTH);  | 
                                                        |
| 112 | + }  | 
                                                        |
| 113 | +  | 
                                                        |
| 114 | + public static function setGregorianYearForDate(int $year, IntlCalendar $calendar): IntlCalendar  | 
                                                        |
| 115 | +    { | 
                                                        |
| 116 | + $datetime = $calendar->toDateTime();  | 
                                                        |
| 117 | +        $yearDiff = $year - (int) $datetime->format('Y'); | 
                                                        |
| 118 | +  | 
                                                        |
| 119 | + $calendar->set(IntlCalendar::FIELD_YEAR, $calendar->get(IntlCalendar::FIELD_YEAR) + $yearDiff);  | 
                                                        |
| 120 | +        if ($calendar->toDateTime()->format('Y') < $year) { | 
                                                        |
| 121 | + $calendar->set(IntlCalendar::FIELD_YEAR, $calendar->get(IntlCalendar::FIELD_YEAR) + 1);  | 
                                                        |
| 122 | + }  | 
                                                        |
| 123 | +        if ($calendar->toDateTime()->format('Y') > $year) { | 
                                                        |
| 124 | + $calendar->set(IntlCalendar::FIELD_YEAR, $calendar->get(IntlCalendar::FIELD_YEAR) - 1);  | 
                                                        |
| 125 | + }  | 
                                                        |
| 126 | +  | 
                                                        |
| 127 | + return $calendar;  | 
                                                        |
| 128 | + }  | 
                                                        |
| 129 | +  | 
                                                        |
| 130 | + public function getWeekdayForGregorianYear(int $year): int  | 
                                                        |
| 131 | +    { | 
                                                        |
| 132 | + $cal = $this->getDayForGregorianYear($year);  | 
                                                        |
| 133 | +  | 
                                                        |
| 134 | + return $cal->get(IntlCalendar::FIELD_DAY_OF_WEEK);  | 
                                                        |
| 135 | + }  | 
                                                        |
| 136 | +  | 
                                                        |
| 137 | + private function getDayForGregorianYear(int $gregorianYear): IntlCalendar  | 
                                                        |
| 138 | +    { | 
                                                        |
| 139 | + $cal = clone $this->calendar;  | 
                                                        |
| 140 | + $cal->set(IntlCalendar::FIELD_MONTH, $this->month - 1);  | 
                                                        |
| 141 | + $cal->set(IntlCalendar::FIELD_DAY_OF_MONTH, $this->day);  | 
                                                        |
| 142 | +  | 
                                                        |
| 143 | + return self::setGregorianYearForDate($gregorianYear, $cal);  | 
                                                        |
| 144 | + }  | 
                                                        |
| 145 | 145 | }  | 
                                                        
@@ -16,16 +16,16 @@  | 
                                                    ||
| 16 | 16 | |
| 17 | 17 | class EasterOrthodoxFactory implements ItemFromDomElementCreator  | 
                                                        
| 18 | 18 |  { | 
                                                        
| 19 | - public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 20 | -	{ | 
                                                        |
| 21 | -		if ($element->nodeName !== 'easterorthodox') { | 
                                                        |
| 22 | - return null;  | 
                                                        |
| 23 | - }  | 
                                                        |
| 19 | + public function itemFromDomElement(DOMElement $element): ?HolidayIteratorItemInterface  | 
                                                        |
| 20 | +    { | 
                                                        |
| 21 | +        if ($element->nodeName !== 'easterorthodox') { | 
                                                        |
| 22 | + return null;  | 
                                                        |
| 23 | + }  | 
                                                        |
| 24 | 24 | |
| 25 | - return new EasterOrthodox(  | 
                                                        |
| 26 | - $element->textContent,  | 
                                                        |
| 27 | -			$element->getAttribute('free') === "true", | 
                                                        |
| 28 | -			(int) $element->getAttribute('offset') | 
                                                        |
| 29 | - );  | 
                                                        |
| 30 | - }  | 
                                                        |
| 25 | + return new EasterOrthodox(  | 
                                                        |
| 26 | + $element->textContent,  | 
                                                        |
| 27 | +            $element->getAttribute('free') === "true", | 
                                                        |
| 28 | +            (int) $element->getAttribute('offset') | 
                                                        |
| 29 | + );  | 
                                                        |
| 30 | + }  | 
                                                        |
| 31 | 31 | }  |