Skip to content

Commit

Permalink
Merge pull request #99 from mogic-le/geo-float
Browse files Browse the repository at this point in the history
Fix GEO coordinates on locale with comma as decimal separator
  • Loading branch information
freekmurze authored Oct 26, 2022
2 parents 789422f + bbd3551 commit 128d8fe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Properties/CoordinatesProperty.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function __construct(string $name, float $lat, float $lng)

public function getValue(): string
{
return "{$this->lat};{$this->lng}";
return json_encode($this->lat) . ';' . json_encode($this->lng);
}

public function getOriginalValue(): array
Expand Down
12 changes: 12 additions & 0 deletions tests/Properties/CoordinatesPropertyTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

namespace Spatie\IcalendarGenerator\Tests\Properties;

use Spatie\IcalendarGenerator\Properties\CoordinatesProperty;
use Spatie\IcalendarGenerator\Tests\PropertyExpectation;

Expand All @@ -11,3 +13,13 @@
->expectOutput('10.5;20.5')
->expectValue(['lat' => 10.5, 'lng' => 20.5]);
});

test('it_has_dot_as_decimal_point', function () {
setlocale(LC_ALL, 'de_DE.UTF-8');
$propertyType = new CoordinatesProperty('GEO', 10.5, 20.5);

PropertyExpectation::create($propertyType)
->expectName('GEO')
->expectOutput('10.5;20.5')
->expectValue(['lat' => 10.5, 'lng' => 20.5]);
});

0 comments on commit 128d8fe

Please sign in to comment.