Skip to content

Commit

Permalink
feat: SURVEY-17487 Optional show zero seconds
Browse files Browse the repository at this point in the history
  • Loading branch information
egeofalcao committed Jun 21, 2023
1 parent c8a6509 commit 9b41bd1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/utils/bearing.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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", () => {
Expand Down
13 changes: 10 additions & 3 deletions src/utils/bearing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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;
Expand Down Expand Up @@ -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}'`;
}
Expand Down

0 comments on commit 9b41bd1

Please sign in to comment.