diff --git a/src/icalendar/prop/geo.py b/src/icalendar/prop/geo.py index c598b03a2..c0a03c9c2 100644 --- a/src/icalendar/prop/geo.py +++ b/src/icalendar/prop/geo.py @@ -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}" diff --git a/src/icalendar/tests/prop/test_vGeo.py b/src/icalendar/tests/prop/test_vGeo.py new file mode 100644 index 000000000..c485acf10 --- /dev/null +++ b/src/icalendar/tests/prop/test_vGeo.py @@ -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