Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

php 8.2 compat #3

Merged
merged 1 commit into from
May 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/php-unit-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 ../..;"
}
}
21 changes: 16 additions & 5 deletions lib/TimeZoneConvert/VTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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),
Expand All @@ -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;
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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,
Expand Down
6 changes: 5 additions & 1 deletion tests/TimeZoneConvert/VTimeZoneTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down
11 changes: 11 additions & 0 deletions tests/docker/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 1 addition & 5 deletions tests/docker/php81/Dockerfile
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions tests/docker/php82/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM php:8.2-alpine

RUN apk add --no-cache php82-pecl-xdebug
Loading