From b2a51851965139e84e580d1093d31f58f0355366 Mon Sep 17 00:00:00 2001 From: mwjames Date: Sun, 30 Sep 2018 12:30:50 +0000 Subject: [PATCH] IcalTimezoneFormatter fix tz-transitions, refs 392, 395 (#435) --- src/iCalendar/IcalTimezoneFormatter.php | 4 +-- .../JSONScript/Fixtures/icalendar-03.1.txt | 4 +-- .../iCalendar/IcalTimezoneFormatterTest.php | 29 ++++++++++++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/iCalendar/IcalTimezoneFormatter.php b/src/iCalendar/IcalTimezoneFormatter.php index d7f6c09d8..5437452ac 100644 --- a/src/iCalendar/IcalTimezoneFormatter.php +++ b/src/iCalendar/IcalTimezoneFormatter.php @@ -87,7 +87,7 @@ public function calcTransitions( $from = null, $to = null ) { continue; } - $transitions = $dateTimezone->getTransitions(); + $transitions = $dateTimezone->getTransitions( $from, $to ); if ( $transitions === false ) { continue; @@ -177,7 +177,7 @@ public function getTransitions() { * @param int $offset */ private function formatTimezoneOffset( $offset ) { - return sprintf( '%s%02d%02d', $offset >= 0 ? '+' : '', floor( $offset ), ( $offset - floor( $offset ) ) * 60 ); + return sprintf( '%s%02d%02d', $offset >= 0 ? '+' : '-', abs( floor( $offset ) ), ( $offset - floor( $offset ) ) * 60 ); } } diff --git a/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt b/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt index d66b8085c..b1821b39d 100644 --- a/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt +++ b/tests/phpunit/Integration/JSONScript/Fixtures/icalendar-03.1.txt @@ -17,8 +17,8 @@ BEGIN:VTIMEZONE TZID:America/New_York BEGIN:STANDARD DTSTART:.* -TZOFFSETFROM:-400 -TZOFFSETTO:-500 +TZOFFSETFROM:-0500 +TZOFFSETTO:-0500 TZNAME:EST END:STANDARD END:VTIMEZONE diff --git a/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php b/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php index ab0b8cf6f..858af78b5 100644 --- a/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php +++ b/tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php @@ -55,7 +55,34 @@ public function transitionsProvider() { 'UTC', 1, 2, - "BEGIN:VTIMEZONE\r\nTZID:UTC\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\nTZOFFSETFROM:+0000\r\nTZOFFSETTO:+0000\r\nTZNAME:UTC\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + "BEGIN:VTIMEZONE\r\nTZID:UTC\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + "TZOFFSETFROM:+0000\r\nTZOFFSETTO:+0000\r\nTZNAME:UTC\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + + yield [ + 'Asia/Bangkok', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:Asia/Bangkok\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + // Travis-CI PHP 7 issue, outputs `TZNAME:+07` + // "TZOFFSETFROM:+0700\r\nTZOFFSETTO:+0700\r\nTZNAME:ICT\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + "TZOFFSETFROM:+0700\r\nTZOFFSETTO:+0700\r\nTZNAME:.*\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + + yield [ + 'Asia/Tokyo', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:Asia/Tokyo\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + "TZOFFSETFROM:+0900\r\nTZOFFSETTO:+0900\r\nTZNAME:JST\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" + ]; + + yield [ + 'America/New_York', + 1, + 2, + "BEGIN:VTIMEZONE\r\nTZID:America/New_York\r\nBEGIN:STANDARD\r\nDTSTART:.*\r\n" . + "TZOFFSETFROM:-0500\r\nTZOFFSETTO:-0500\r\nTZNAME:EST\r\nEND:STANDARD\r\nEND:VTIMEZONE\r\n" ]; }