Skip to content

Commit 672129d

Browse files
Geographic Distance: format travel time as hours and minutes
1 parent 392a9e6 commit 672129d

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Geographic Distance/geographic_distance.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,16 @@ def km_to_miles(km: float) -> float:
3030
"""Convert kilometers to miles."""
3131
return km * 0.621371
3232

33+
def format_travel_time(hours: float) -> str:
34+
"""Format fractional hours as 'Hh Mm'."""
35+
h = int(hours)
36+
m = int(round((hours - h) * 60))
37+
if m == 60:
38+
h += 1
39+
m = 0
40+
return f"{h}h {m}m"
41+
42+
3343

3444

3545

0 commit comments

Comments
 (0)