diff --git a/src/utils/bearing.test.ts b/src/utils/bearing.test.ts index a65d080a..de128057 100644 --- a/src/utils/bearing.test.ts +++ b/src/utils/bearing.test.ts @@ -31,6 +31,8 @@ describe("bearing", () => { expect(convertDDToDMS(300, false, false)).toBe("300° 00'"); expect(convertDDToDMS(300.1, false, false)).toBe("300° 10'"); expect(convertDDToDMS(0, false)).toBe("0° 00'"); + expect(convertDDToDMS(300, false, false, true)).toBe("300° 00' 00\""); + expect(convertDDToDMS(0, false, false, true)).toBe("0° 00' 00\""); }); test("bearingStringValidator", () => { diff --git a/src/utils/bearing.ts b/src/utils/bearing.ts index d0dd5ee3..b450aa42 100644 --- a/src/utils/bearing.ts +++ b/src/utils/bearing.ts @@ -12,9 +12,9 @@ export const bearingCorrectionValueFormatter = (value: any): string => { return "–"; } if (typeof safeValue === "string") { - return convertDDToDMS(bearingNumberParser(safeValue), true, true); + return convertDDToDMS(bearingNumberParser(safeValue), true, true, true); } - return convertDDToDMS(safeValue, true, true); + return convertDDToDMS(safeValue, true, true, true); }; export const bearingNumberParser = (value: string): number | null => { @@ -41,7 +41,12 @@ export const bearingStringValidator = ( }; // Decimal-ish degrees to Degrees Minutes Seconds converter -export const convertDDToDMS = (dd: number | null, showPositiveSymbol = true, addTrailingZeros = true): string => { +export const convertDDToDMS = ( + dd: number | null, + showPositiveSymbol = true, + addTrailingZeros = true, + showZeroSeconds = false, +): string => { if (dd == null) return "–"; if (dd === 0) addTrailingZeros = false; @@ -75,6 +80,8 @@ export const convertDDToDMS = (dd: number | null, showPositiveSymbol = true, add dmsString += `\xa0${minString}'\xa0${secString}.${deciSecString}"`; // "\xa0" is here for non-breaking space } else if (secNumeric != 0) { dmsString += `\xa0${minString}'\xa0${secString}"`; + } else if (showZeroSeconds && secNumeric == 0) { + dmsString += `\xa0${minString}'\xa000"`; } else { dmsString += `\xa0${minString}'`; }