dd_to_hms
- ssapy.utils.dd_to_hms(degree_decimal)[source][source]
Converts Decimal Degrees (DD) to Hour-Minute-Second (HMS) format.
Parameters:
- degree_decimal (float or str):
A decimal degree value (float) to be converted to HMS format.
If the input is a string in DMS format (e.g., “12:34:56”), it will be converted to DD using the dms_to_dd function before processing.
Returns:
- str: A string representing the HMS format (e.g., “12:34:56”). The format includes:
Hours as an integer.
Minutes as an integer.
Seconds as a float (rounded to 4 decimal places if necessary).
Notes:
Decimal degrees are wrapped into [0, 360) and divided by 15 to convert to hours, so the result always lies in [0, 24) h.
Handles edge cases where seconds reach 60, incrementing minutes accordingly.
Returns seconds as an integer if the value is a whole number.
Example:
>>> dd_to_hms(188.73333333333332) '12:34:56'
>>> dd_to_hms(-236.375) '8:14:30' # -236.375 deg is 123.625 deg.
>>> dd_to_hms("12:34:56") # DMS string converted to DD first. '0:50:18.4'