diff --git a/.github/workflows/php-unit-test.yml b/.github/workflows/php-unit-test.yml index 8168ccb..585477e 100644 --- a/.github/workflows/php-unit-test.yml +++ b/.github/workflows/php-unit-test.yml @@ -18,7 +18,7 @@ jobs: strategy: matrix: operating-system: [ubuntu-20.04] - php-versions: ['7.4', '8.0', '8.1'] + php-versions: ['7.4', '8.0', '8.1', '8.2'] name: PHP ${{ matrix.php-versions }} Test on ${{ matrix.operating-system }} steps: diff --git a/composer.json b/composer.json index 0e92c79..0d15510 100644 --- a/composer.json +++ b/composer.json @@ -18,6 +18,7 @@ }, "scripts": { "php8test": "cd tests/docker; docker-compose run cli8 ash -c 'cd /src/tests; ../vendor/bin/phpunit --color TimeZoneConvert/AllTests.php'; cd ../..;", - "php81test": "cd tests/docker; docker-compose run cli81 ash -c 'cd /src/tests; ../vendor/bin/phpunit --color TimeZoneConvert/AllTests.php'; cd ../..;" + "php81test": "cd tests/docker; docker-compose run cli81 ash -c 'cd /src/tests; ../vendor/bin/phpunit --color TimeZoneConvert/AllTests.php'; cd ../..;", + "php82test": "cd tests/docker; docker-compose run cli82 ash -c 'cd /src/tests; ../vendor/bin/phpunit --color TimeZoneConvert/AllTests.php'; cd ../..;" } } diff --git a/lib/TimeZoneConvert/VTimeZone.php b/lib/TimeZoneConvert/VTimeZone.php index cfeef6f..c4c5854 100644 --- a/lib/TimeZoneConvert/VTimeZone.php +++ b/lib/TimeZoneConvert/VTimeZone.php @@ -17,7 +17,16 @@ class TimeZoneConvert_VTimeZone { const EOL = "\r\n"; - + + protected $dateFormat = 'Y-m-d\TH:i:sP'; // DateTime::DATE_ATOM NOTE: In contrast to the docs Y is used instead of X + + public function __construct() + { + if (PHP_VERSION_ID < 80200) { + $this->dateFormat = 'Y-m-d\TH:i:sO'; // DateTime::ISO8601; + } + } + /** * gets php's DateTimeZone identifier from given VTIMEZONE and optional prodid * @@ -65,7 +74,7 @@ public function getVTimezone($tzid, $from=NULL, $until=NULL) $timezone = new DateTimeZone($tzid); $transitions = TimeZoneConvert_Transition::getTransitions($timezone, $from, $until); - + $splitedTransitions = array( 'DAYLIGHT' => $transitions->filter('isdst', TRUE), 'STANDART' => $transitions->filter('isdst', FALSE), @@ -80,7 +89,9 @@ public function getVTimezone($tzid, $from=NULL, $until=NULL) $transitionRule = TimeZoneConvert_TransitionRule::createFromTransition($transitions->getFirst()); foreach($transitions as $transition) { $expectedTransitionDate = $transitionRule->computeTransitionDate(substr($transition['time'], 0, 4)); - if ($expectedTransitionDate->format(DateTime::ISO8601) != $transition['time']) { + if ($expectedTransitionDate->format($this->dateFormat) != $transition['time']) { + echo $expectedTransitionDate->format($this->dateFormat) ."\n"; + echo $transition['time'] ."\n"; $useRrule = FALSE; break; } @@ -95,7 +106,7 @@ public function getVTimezone($tzid, $from=NULL, $until=NULL) foreach ($backTransitions as $backTransition) { $expectedTransitionDate = $transitionRule->computeTransitionDate(substr($backTransition['time'], 0, 4)); - if ($expectedTransitionDate->format(DateTime::ISO8601) != $backTransition['time']) { + if ($expectedTransitionDate->format($this->dateFormat) != $backTransition['time']) { break; } @@ -231,7 +242,7 @@ public function getTransitions($transitionRules) foreach($transitionDates as $transitionDate) { $transitions->addModel(new TimeZoneConvert_Transition(array( 'ts' => $transitionDate->getTimestamp(), - 'date' => $transitionDate->format(DateTime::ISO8601), + 'date' => $transitionDate->format($this->dateFormat), 'offset' => $transitionRule->offset, 'isdst' => $transitionRule->isdst, 'abbr' => $transitionRule->abbr, diff --git a/tests/TimeZoneConvert/VTimeZoneTests.php b/tests/TimeZoneConvert/VTimeZoneTests.php index 8f8e310..8456b2f 100644 --- a/tests/TimeZoneConvert/VTimeZoneTests.php +++ b/tests/TimeZoneConvert/VTimeZoneTests.php @@ -260,7 +260,11 @@ public function testGetTransitionsRfc5545AmericaNewYork() $this->assertTrue(count($transitions) > 7, 'min. 7 transitions should be computed'); $this->assertEquals(-84387600, $transitions[0]['ts']); - $this->assertEquals('1967-04-30T07:00:00+0000', $transitions[0]['date']); + if (PHP_VERSION_ID < 80200) { + $this->assertEquals('1967-04-30T07:00:00+0000', $transitions[0]['date']); + } else { + $this->assertEquals('1967-04-30T07:00:00+00:00', $transitions[0]['date']); + } $this->assertEquals(-14400, $transitions[0]['offset']); $this->assertEquals(TRUE, $transitions[0]['isdst']); $this->assertEquals('EDT', $transitions[0]['abbr']); diff --git a/tests/docker/docker-compose.yml b/tests/docker/docker-compose.yml index 4583983..c724591 100644 --- a/tests/docker/docker-compose.yml +++ b/tests/docker/docker-compose.yml @@ -22,6 +22,17 @@ services: # needed by PHPSTORM for debugging PHP_IDE_CONFIG: "serverName=timezoneconvert" + cli82: + build: ./php82/ + volumes: + - ../../:/src/ + - ./xdebug.ini:/usr/local/etc/php/conf.d/xdebug.ini:ro + networks: + - external_network + environment: + # needed by PHPSTORM for debugging + PHP_IDE_CONFIG: "serverName=timezoneconvert" + networks: external_network: driver: bridge diff --git a/tests/docker/php81/Dockerfile b/tests/docker/php81/Dockerfile index c2b4fde..38d8de2 100644 --- a/tests/docker/php81/Dockerfile +++ b/tests/docker/php81/Dockerfile @@ -1,7 +1,3 @@ FROM php:8.1-alpine -RUN apk add --no-cache $PHPIZE_DEPS \ - && pecl install xdebug \ - && docker-php-ext-enable xdebug - -#RUN apk add --no-cache php8-pecl-xdebug +RUN apk add --no-cache php81-pecl-xdebug diff --git a/tests/docker/php82/Dockerfile b/tests/docker/php82/Dockerfile new file mode 100644 index 0000000..e3e29a0 --- /dev/null +++ b/tests/docker/php82/Dockerfile @@ -0,0 +1,3 @@ +FROM php:8.2-alpine + +RUN apk add --no-cache php82-pecl-xdebug