Bug 1342394 - Use standard pad functions in Telemetry JS modules r=gfritzsche
authorflyingrub
Wed, 01 Mar 2017 19:06:08 +0100
changeset 345957 1406a5dfed25
parent 345956 8947d02cec5d
child 345958 323e5db6b459
push id38367
push usercbook@mozilla.com
push dateSun, 05 Mar 2017 19:57:42 +0000
treeherderautoland@1406a5dfed25 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgfritzsche
bugs1342394
milestone54.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1342394 - Use standard pad functions in Telemetry JS modules r=gfritzsche Replaced the handmade padding funciton by padStart MozReview-Commit-ID: 6UyTo4OZYv4
toolkit/components/telemetry/TelemetryStorage.jsm
toolkit/components/telemetry/TelemetryUtils.jsm
--- 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)