Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
  • Loading branch information
Christopher Szu committed Dec 28, 2023
1 parent 7fc1528 commit 0c46f6a
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 55 deletions.
2 changes: 1 addition & 1 deletion lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ private function jumpForward(DateTimeInterface $dt)
isset($previousDate) && $this->currentDate = clone $previousDate;

// We don't know the counter at this point anymore
$this->counter = NAN;
$this->counter = (int) NAN;

// It's possible that we miss the previous occurrence by jumping too much, in this case we reset the rrule and
// do the normal forward.
Expand Down
2 changes: 1 addition & 1 deletion lib/TimezoneGuesser/FindFromMzVersionTimezone.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
class FindFromMzVersionTimezone implements TimezoneFinder
{
public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone
public function find(string $tzid, ?bool $failIfUncertain = false): ?DateTimeZone
{
if (strlen($tzid) < 1) {
return null;
Expand Down
10 changes: 4 additions & 6 deletions lib/TimezoneGuesser/FindFromOffsetName.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,9 @@

namespace Sabre\VObject\TimezoneGuesser;

use DateTimeZone;

class FindFromOffsetName implements TimezoneFinder
{
public static $offsetTimezones = [
public static array $offsetTimezones = [
'+01:00' => 'Africa/Lagos',
'+02:00' => 'Africa/Cairo',
'+03:00' => 'Europe/Moscow',
Expand All @@ -35,17 +33,17 @@ class FindFromOffsetName implements TimezoneFinder
'-11:00' => 'Pacific/Niue',
];

public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone
public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone
{
// only handle number timezone
if (strlen($tzid) > 6) {
return null;
}

try {
$tzid = new DateTimeZone($tzid);
$tzid = new \DateTimeZone($tzid);

return new DateTimeZone(self::$offsetTimezones[$tzid->getName()]) ?? null;
return new \DateTimeZone(self::$offsetTimezones[$tzid->getName()]) ?? null;
} catch (\Exception $e) {
return null;
}
Expand Down
8 changes: 3 additions & 5 deletions lib/TimezoneGuesser/FindFromOutlookCities.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

namespace Sabre\VObject\TimezoneGuesser;

use DateTimeZone;

class FindFromOutlookCities implements TimezoneFinder
{
/**
* Example: TZID:(UTC+01:00) Bruxelles\, København\, Madrid\, Paris
*/
public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone
public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone
{
$tzid = preg_replace('/TZID:\(UTC(\+|\-)\d{2}:\d{2}\)/', '', $tzid, -1, $count);
if ($count === 0) {
Expand All @@ -29,12 +27,12 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone
return null;
}

$tzIdentifiers = DateTimeZone::listIdentifiers();
$tzIdentifiers = \DateTimeZone::listIdentifiers();

foreach ($cities as $city) {
foreach ($tzIdentifiers as $tzIdentifier) {
if (str_contains(strtolower($tzIdentifier), strtolower($city))) {
return new DateTimeZone($tzIdentifier);
return new \DateTimeZone($tzIdentifier);
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,19 @@

namespace Sabre\VObject\TimezoneGuesser;

use DateTimeZone;
use DateTimeImmutable;
use Sabre\VObject\Component\VTimeZone;
use Sabre\VObject\Recur\RRuleIterator;
use Sabre\VObject\TimeZoneUtil;

class GuessFromCustomizedTimeZone implements TimezoneGuesser
{
public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?DateTimeZone
public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\DateTimeZone
{
if (null === $vtimezone->TZID || $vtimezone->TZID->getValue() !== 'Customized Time Zone') {
return null;
}

$timezones = DateTimeZone::listIdentifiers();
$timezones = \DateTimeZone::listIdentifiers();
$standard = $vtimezone->STANDARD;
$daylight = $vtimezone->DAYLIGHT;
if (!$standard) {
Expand All @@ -34,8 +32,8 @@ public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?Dat
$standardRRule = $standard->RRULE ? $standard->RRULE->getValue() : 'FREQ=DAILY';
// The guess will not be perfectly matched since we use the timezone data of the current year
// It might be wrong if the timezone data changed in the past
$year = (new DateTimeImmutable('now'))->format('Y');
$start = new DateTimeImmutable($year . '-01-01');
$year = (new \DateTimeImmutable('now'))->format('Y');
$start = new \DateTimeImmutable($year . '-01-01');
$standardIterator = new RRuleIterator($standardRRule, $start);
$standardIterator->next();

Expand All @@ -48,7 +46,7 @@ public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?Dat
$daylightIterator && $daylightIterator->next();

foreach ($timezones as $timezone) {
$tz = new DateTimeZone($timezone);
$tz = new \DateTimeZone($timezone);
// check standard
$timestamp = $standardIterator->current()->getTimestamp();
$transitions = $tz->getTransitions($timestamp, $timestamp + 1);
Expand Down
8 changes: 3 additions & 5 deletions lib/TimezoneGuesser/LowercaseTimezoneIdentifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@

namespace Sabre\VObject\TimezoneGuesser;

use DateTimeZone;

class LowercaseTimezoneIdentifier implements TimezoneFinder
{
public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone
public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone
{
foreach (DateTimeZone::listIdentifiers() as $timezone) {
foreach (\DateTimeZone::listIdentifiers() as $timezone) {
if (strtolower($tzid) === strtolower($timezone)) {
return new DateTimeZone($timezone);
return new \DateTimeZone($timezone);
}
}

Expand Down
30 changes: 0 additions & 30 deletions tests/VObject/VCardConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,36 +608,6 @@ public function testPhoneNumberValueTypeGetsRemoved(): void
$vcard = Reader::read($input);
$vcard = $vcard->convert(Document::VCARD40);

self::assertVObjectEqualsVObject(
$output,
$vcard
);
}

public function testPhoneNumberValueTypeGetsRemoved(): void
{
$input = <<<VCF
BEGIN:VCARD
VERSION:3.0
UID:foo
FN:John Doe
TEL;TYPE=HOME;VALUE=PHONE-NUMBER:+1234
END:VCARD
VCF;

$output = <<<VCF
BEGIN:VCARD
VERSION:4.0
UID:foo
FN:John Doe
TEL;TYPE=HOME:+1234
END:VCARD
VCF;

$vcard = Reader::read($input);
$vcard = $vcard->convert(Document::VCARD40);

$this->assertVObjectEqualsVObject(
$output,
$vcard
Expand Down

0 comments on commit 0c46f6a

Please sign in to comment.