Skip to content

Commit

Permalink
IcalTimezoneFormatter fix tz-transitions, refs 392, 395 (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
mwjames committed Sep 30, 2018
1 parent db71c4f commit b2a5185
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/iCalendar/IcalTimezoneFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function calcTransitions( $from = null, $to = null ) {
continue;
}

$transitions = $dateTimezone->getTransitions();
$transitions = $dateTimezone->getTransitions( $from, $to );

if ( $transitions === false ) {
continue;
Expand Down Expand Up @@ -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 );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion tests/phpunit/Unit/iCalendar/IcalTimezoneFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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"
];
}

Expand Down

0 comments on commit b2a5185

Please sign in to comment.