Skip to content

Commit

Permalink
Merge pull request #23 from longitude-one/21-60-minutes-do-not-throw-…
Browse files Browse the repository at this point in the history
…range-exception

Fix "geo-parser miss some out-of-ranges"
  • Loading branch information
Alexandre-T authored May 23, 2024
2 parents d7c6088 + 96b79ed commit 39b17ba
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/LongitudeOne/Geo/String/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private function minutes(): string|int
$readMinutes = $this->match(Lexer::T_INTEGER);

// Throw exception if minutes are greater than 60
if ($readMinutes > 60) {
if ($readMinutes >= 60) {
throw new RangeException($this->input, RangeException::MINUTES_OUT_OF_RANGE);
}

Expand All @@ -276,7 +276,7 @@ private function minutes(): string|int
$minutes = $this->match(Lexer::T_FLOAT);

// Throw exception if minutes are greater than 60
if ($minutes > 60) {
if ($minutes >= 60) {
throw new RangeException($this->input, RangeException::MINUTES_OUT_OF_RANGE);
}

Expand Down Expand Up @@ -361,7 +361,7 @@ private function seconds(): int|string
$seconds = $this->number();

// Throw exception if seconds are greater than 60
if ($seconds > 60) {
if ($seconds >= 60) {
throw new RangeException($this->input, RangeException::SECONDS_OUT_OF_RANGE);
}

Expand Down
19 changes: 19 additions & 0 deletions tests/LongitudeOne/Geo/String/Tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ public static function dataSourceBad(): \Generator
yield ['55:200:32', RangeException::class, '[RangeException] Minutes must be between 0 and 59, got "55:200:32".'];
yield ['55:20:99', RangeException::class, '[RangeException] Seconds must be between 0 and 59, got "55:20:99".'];
yield ['55°70.99\'', RangeException::class, '[RangeException] Minutes must be between 0 and 59, got "55°70.99\'".'];
// Issue #21
yield ['55°60.17\'', RangeException::class, '[RangeException] Minutes must be between 0 and 59, got "55°60.17\'".'];
yield ['55:60:32', RangeException::class, '[RangeException] Minutes must be between 0 and 59, got "55:60:32".'];
yield ['55:20:60', RangeException::class, '[RangeException] Seconds must be between 0 and 59, got "55:20:60".'];
yield ['180°20\'20"W', RangeException::class, '[RangeException] Longitude must be between -180 and 180, got "180°20\'20"W".'];
yield ['180°20\'20"E', RangeException::class, '[RangeException] Longitude must be between -180 and 180, got "180°20\'20"E".'];
yield ['90°20\'20"S', RangeException::class, '[RangeException] Latitude must be between -90 and 90, got "90°20\'20"S".'];
yield ['90°20\'20"N', RangeException::class, '[RangeException] Latitude must be between -90 and 90, got "90°20\'20"N".'];
}

/**
Expand Down Expand Up @@ -168,6 +176,17 @@ public static function dataSourceGood(): \Generator
yield ['79°56′55″W, 40°26′46″N', [-79.94861111111111, 40.44611111111111]];
yield ['1e-5°N 1e-5°W', [0.00001, -0.00001]];

// Issue #21
yield ['180°00\'00"W, 90°00\'00"S', [-180, -90]];
yield ['180°00\'00"E, 90°00\'00"N', [180, 90]];
yield ['180:00:00E, 90:00:00N', [180, 90]];
yield ['180:00:00W, 90:00:00S', [-180, -90]];
yield ['55°17.60\'', 55.29333333333333];
yield [180, 180];
yield ['180.0', 180.0];
yield [-180, -180];
yield ['-180.0', -180.0];

// Documentation tests

// Simple single-signed values
Expand Down

0 comments on commit 39b17ba

Please sign in to comment.