Skip to content

Commit d309839

Browse files
committed
[FIX] format: wrong internal format conversion
In internal format, the "mm" of minutes is converted to "MM", to be distinct from "mm" of months. But the conversion wasn't done when converting back to a format string. closes #7246 Task: 5126306 X-original-commit: 0aa0e39 Signed-off-by: Lucas Lefèvre (lul) <[email protected]> Signed-off-by: Adrien Minne (adrm) <[email protected]>
1 parent 5d722a7 commit d309839

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/helpers/format/format_parser.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function tokensToTextInternalFormat(
284284
* Replace in place tokens "mm" and "m" that denote minutes in date format with "MM" to avoid confusion with months.
285285
*
286286
* As per OpenXML specification, in date formats if a date token "m" or "mm" is followed by a date token "s" or
287-
* preceded by a data token "h", then it's not a month but an minute.
287+
* preceded by a data token "h", then it's not a month but a minute.
288288
*/
289289
function convertTokensToMinutesInDateFormat(tokens: DateInternalFormat["tokens"]) {
290290
const dateParts = tokens.filter((token) => token.type === "DATE_PART") as DatePartToken[];
@@ -332,6 +332,9 @@ function internalFormatPartToFormat(
332332
case "REPEATED_CHAR":
333333
format += "*" + token.value;
334334
break;
335+
case "DATE_PART":
336+
format += token.value === "MM" ? "mm" : token.value; // Convert "MM" back to "mm" for minutes
337+
break;
335338
default:
336339
format += token.value;
337340
}

tests/formats/format_helpers.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,6 +1053,7 @@ describe("rounding format", () => {
10531053
expect(roundFormat("ddd-mm-yyyy")).toBe("ddd-mm-yyyy");
10541054
expect(roundFormat("#,##0,,")).toBe("#,##0,,");
10551055
expect(roundFormat("#,##0.00,")).toBe("#,##0,");
1056+
expect(roundFormat("hh:mm:ss")).toBe("hh:mm:ss");
10561057
});
10571058

10581059
test("Round multi part format", () => {

0 commit comments

Comments
 (0)