diff --git a/RELEASE-NOTES.md b/RELEASE-NOTES.md index 3d0451c44..c1f79f340 100644 --- a/RELEASE-NOTES.md +++ b/RELEASE-NOTES.md @@ -5,8 +5,9 @@ different releases and which versions of PHP and MediaWiki they support, see the ## Maps 6.0.2 -Under development +Released on October 1st, 2018. +* Coordinates formatted as Decimal Degrees or Float are now rounded sensibly * The `smgQPCoodDirectional` setting is no longer ignored ## Maps 6.0.1 diff --git a/src/CoordinateFormatter.php b/src/CoordinateFormatter.php index 47794d5c4..5e72754b5 100644 --- a/src/CoordinateFormatter.php +++ b/src/CoordinateFormatter.php @@ -14,12 +14,19 @@ */ class CoordinateFormatter { + private const PRECISION_MAP = [ + 'dms' => 1 / 360000, + 'dm' => 1 / 600000, + 'dd' => 1 / 1000000, + 'float' => 1 / 1000000, + ]; + public function format( LatLongValue $latLong, string $format, bool $directional ) { $formatter = new LatLongFormatter( new FormatterOptions( [ LatLongFormatter::OPT_FORMAT => $format, LatLongFormatter::OPT_DIRECTIONAL => $directional, - LatLongFormatter::OPT_PRECISION => 1 / 360000 + LatLongFormatter::OPT_PRECISION => self::PRECISION_MAP[$format] ] ) ); diff --git a/tests/Integration/Parser/CoordinatesTest.php b/tests/Integration/Parser/CoordinatesTest.php index c7a5a110d..4ec716303 100644 --- a/tests/Integration/Parser/CoordinatesTest.php +++ b/tests/Integration/Parser/CoordinatesTest.php @@ -65,4 +65,32 @@ public function testGivenInvalidFormat_defaultFormatGetsUsed() { ); } + public function testRoundingWhenFormattingAsFloat() { + $this->assertContains( + '52.136945 N, 0.466722 W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=float}}' ) + ); + } + + public function testRoundingWhenFormattingAsDMS() { + $this->assertContains( + '52° 8\' 13.00" N, 0° 28\' 0.20" W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=dms}}' ) + ); + } + + public function testRoundingWhenFormattingAsDD() { + $this->assertContains( + '52.136945° N, 0.466722° W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=dd}}' ) + ); + } + + public function testRoundingWhenFormattingAsDM() { + $this->assertContains( + '52° 8.2167\' N, 0° 28.0033\' W', + $this->parse( '{{#coordinates:52.136945,-0.466722|format=dm}}' ) + ); + } + } \ No newline at end of file