Bug 1342394 - Use standard pad functions in Telemetry JS modules
Replaced the handmade padding funciton by padStart
MozReview-Commit-ID: 6UyTo4OZYv4
--- a/toolkit/components/telemetry/TelemetryStorage.jsm
+++ b/toolkit/components/telemetry/TelemetryStorage.jsm
@@ -1803,22 +1803,21 @@ function getPingDirectory() {
/**
* Build the path to the archived ping.
* @param {String} aPingId The ping id.
* @param {Object} aDate The ping creation date.
* @param {String} aType The ping type.
* @return {String} The full path to the archived ping.
*/
function getArchivedPingPath(aPingId, aDate, aType) {
- // Helper to pad the month to 2 digits, if needed (e.g. "1" -> "01").
- let addLeftPadding = value => (value < 10) ? ("0" + value) : value;
// Get the ping creation date and generate the archive directory to hold it. Note
// that getMonth returns a 0-based month, so we need to add an offset.
+ let month = new String(aDate.getMonth() + 1);
let archivedPingDir = OS.Path.join(gPingsArchivePath,
- aDate.getFullYear() + "-" + addLeftPadding(aDate.getMonth() + 1));
+ aDate.getFullYear() + "-" + month.padStart(2, "0"));
// Generate the archived ping file path as YYYY-MM/<TIMESTAMP>.UUID.type.json
let fileName = [aDate.getTime(), aPingId, aType, "json"].join(".");
return OS.Path.join(archivedPingDir, fileName);
}
/**
* Get the size of the ping file on the disk.
* @return {Integer} The file size, in bytes, of the ping file or 0 on errors.
--- a/toolkit/components/telemetry/TelemetryUtils.jsm
+++ b/toolkit/components/telemetry/TelemetryUtils.jsm
@@ -121,22 +121,18 @@ this.TelemetryUtils = {
/**
* Date.toISOString() gives us UTC times, this gives us local times in
* the ISO date format. See http://www.w3.org/TR/NOTE-datetime
* @param {Object} date The input date.
* @return {String} The local time ISO string.
*/
toLocalTimeISOString(date) {
- function padNumber(number, places) {
- number = number.toString();
- while (number.length < places) {
- number = "0" + number;
- }
- return number;
+ function padNumber(number, length) {
+ return number.toString().padStart(length, "0");
}
let sign = (n) => n >= 0 ? "+" : "-";
// getTimezoneOffset counter-intuitively returns -60 for UTC+1.
let tzOffset = -date.getTimezoneOffset();
// YYYY-MM-DDThh:mm:ss.sTZD (eg 1997-07-16T19:20:30.45+01:00)
return padNumber(date.getFullYear(), 4)