Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/icalendar/prop/geo.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ def __init__(
self.longitude = longitude
self.params = Parameters(params)

@property
def ical_value(self) -> tuple[float, float]:
"""Return the Python tuple value (latitude, longitude).

This property provides access to the underlying geographic coordinates
as a tuple of floats.

Returns:
tuple[float, float]: A tuple of (latitude, longitude) in decimal degrees.
Latitude ranges from -90 to 90 (south to north).
Longitude ranges from -180 to 180 (west to east).

Example:
>>> from icalendar.prop import vGeo
>>> geo = vGeo((37.386013, -122.082932))
>>> geo.ical_value
(37.386013, -122.082932)

See Also:
:rfc:`5545#section-3.8.1.6` for the GEO property specification.
"""
return (self.latitude, self.longitude)

def to_ical(self) -> str:
return f"{self.latitude};{self.longitude}"

Expand Down
37 changes: 37 additions & 0 deletions src/icalendar/tests/prop/test_vGeo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
"""Test vGeo ical_value property."""

from icalendar.prop import vGeo


def test_ical_value_basic():
"""ical_value property returns tuple of (latitude, longitude)."""
geo = vGeo((37.386013, -122.082932))
assert geo.ical_value == (37.386013, -122.082932)
assert isinstance(geo.ical_value, tuple)
assert len(geo.ical_value) == 2


def test_ical_value_components():
"""ical_value property components match latitude and longitude."""
lat, lon = 48.8566, 2.3522 # Paris
geo = vGeo((lat, lon))
assert geo.ical_value[0] == lat
assert geo.ical_value[1] == lon
assert geo.ical_value == (geo.latitude, geo.longitude)


def test_ical_value_from_ical():
"""ical_value property works with geo parsed from ical string."""
coords = vGeo.from_ical("51.5074;-0.1278") # London
geo = vGeo(coords)
assert geo.ical_value == (51.5074, -0.1278)
assert geo.ical_value[0] == 51.5074 # latitude
assert geo.ical_value[1] == -0.1278 # longitude


def test_ical_value_negative_coordinates():
"""ical_value property handles negative coordinates."""
geo = vGeo((-33.8688, 151.2093)) # Sydney
assert geo.ical_value == (-33.8688, 151.2093)
assert geo.ical_value[0] < 0 # Southern hemisphere
assert geo.ical_value[1] > 0 # Eastern hemisphere