Skip to content

Commit b4456ac

Browse files
committed
Web Inspector: remove trailing ".0" for timestamps
https://bugs.webkit.org/show_bug.cgi?id=191122 rdar://problem/166500013 Reviewed by Devin Rousso. Strip trailing zeros from integer duration values to improve readability. For example, "1.00ms" now displays as "1ms". This is achieved by adding `trailingZeroDisplay: "stripIfInteger"` to the `toLocaleString` options in `String.standardFormatters`, which handles this in a locale-aware manner. * LayoutTests/inspector/unit-tests/number-utilities.html: * Source/WebInspectorUI/UserInterface/Base/Utilities.js: (value.f): * Source/WebInspectorUI/UserInterface/Views/FontDetailsPanel.js: (WI.FontDetailsPanel.prototype._formatAxisValueAsString): * Source/WebInspectorUI/UserInterface/Views/FontVariationDetailsSectionRow.js: (WI.FontVariationDetailsSectionRow.prototype._formatAxisValueAsString): Canonical link: https://commits.webkit.org/304851@main
1 parent 9f3fa4f commit b4456ac

File tree

4 files changed

+8
-5
lines changed

4 files changed

+8
-5
lines changed

LayoutTests/inspector/unit-tests/number-utilities.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
InspectorTest.expectEqual(Number.secondsToString(0.123456, false), "123ms", "normal resolution of greater than 100ms but sub 1s should be ms");
4343
InspectorTest.expectEqual(Number.secondsToString(1.123456, false), "1.12s", "normal resolution of greater than 1s but sub 1min should be seconds");
4444
InspectorTest.expectEqual(Number.secondsToString(30.123456, false), "30.12s", "normal resolution of greater than 1s but sub 1min should be seconds");
45-
InspectorTest.expectEqual(Number.secondsToString(60.123456, false), "1.0min", "normal resolution of greater than 1min but sub 1hr should be minutes");
45+
InspectorTest.expectEqual(Number.secondsToString(60.123456, false), "1min", "normal resolution of greater than 1min but sub 1hr should be minutes");
4646
InspectorTest.expectEqual(Number.secondsToString(100.123456, false), "1.7min", "normal resolution of greater than 1min but sub 1hr should be minutes");
4747
InspectorTest.expectEqual(Number.secondsToString(12345, false), "3.4hrs", "normal resolution of greater than 1hr but sub 1 day should be hrs");
4848
InspectorTest.expectEqual(Number.secondsToString(123456, false), "1.4 days", "normal resolution of greater than 1 day should be days");

Source/WebInspectorUI/UserInterface/Base/Utilities.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,8 @@ Object.defineProperty(String, "standardFormatters",
11581158
let options = {
11591159
minimumFractionDigits: token.precision,
11601160
maximumFractionDigits: token.precision,
1161-
useGrouping: false
1161+
useGrouping: false,
1162+
trailingZeroDisplay: "stripIfInteger",
11621163
};
11631164
return value.toLocaleString(undefined, options);
11641165
},
@@ -1321,7 +1322,7 @@ Object.defineProperty(Number, "percentageString",
13211322
{
13221323
value(fraction, precision = 1)
13231324
{
1324-
return fraction.toLocaleString(undefined, {minimumFractionDigits: precision, style: "percent"});
1325+
return fraction.toLocaleString(undefined, {minimumFractionDigits: precision, style: "percent", trailingZeroDisplay: "stripIfInteger"});
13251326
}
13261327
});
13271328

Source/WebInspectorUI/UserInterface/Views/FontDetailsPanel.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,8 @@ WI.FontDetailsPanel = class FontDetailsPanel extends WI.StyleDetailsPanel
297297
minimumFractionDigits: 0,
298298
maximumFractionDigits: 2,
299299
useGrouping: false,
300-
}
300+
trailingZeroDisplay: "stripIfInteger",
301+
};
301302
return value.toLocaleString(undefined, options);
302303
}
303304

Source/WebInspectorUI/UserInterface/Views/FontVariationDetailsSectionRow.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ WI.FontVariationDetailsSectionRow = class FontVariationDetailsSectionRow extends
141141
minimumFractionDigits: 0,
142142
maximumFractionDigits: 2,
143143
useGrouping: false,
144-
}
144+
trailingZeroDisplay: "stripIfInteger",
145+
};
145146
return value.toLocaleString(undefined, options);
146147
}
147148

0 commit comments

Comments
 (0)