Bug 1313797: Remove Date.prototype.toLocaleFormat uses in toolkit/mozapps/extensions/internal. r=mossop
authorAndré Bargull <andre.bargull@gmail.com>
Fri, 28 Oct 2016 15:31:27 -0700
changeset 347382 3a9993173926cfede3e45e1a97c0b9aefd35acb5
parent 347381 394726989b1cd941c3926f8d18a47d4741b7096c
child 347383 cdd2fcf9428117f6b51de4465116ae5e1d841d1a
push id10298
push userraliiev@mozilla.com
push dateMon, 14 Nov 2016 12:33:03 +0000
treeherdermozilla-aurora@7e29173b1641 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs1313797
milestone52.0a1
Bug 1313797: Remove Date.prototype.toLocaleFormat uses in toolkit/mozapps/extensions/internal. r=mossop
toolkit/mozapps/extensions/internal/AddonLogging.jsm
--- a/toolkit/mozapps/extensions/internal/AddonLogging.jsm
+++ b/toolkit/mozapps/extensions/internal/AddonLogging.jsm
@@ -90,26 +90,38 @@ AddonLogger.prototype = {
                          createInstance(Ci.nsIScriptError);
     consoleMessage.init(message, stack.sourceName, null, stack.lineNumber, 0,
                         Ci.nsIScriptError.errorFlag, "component javascript");
     Services.console.logMessage(consoleMessage);
 
     // Always dump errors, in case the Console Service isn't listening yet
     dump("*** " + message + "\n");
 
+    function formatTimestamp(date) {
+      // Format timestamp as: "%Y-%m-%d %H:%M:%S"
+      let year = String(date.getFullYear());
+      let month = String(date.getMonth() + 1).padStart(2, "0");
+      let day = String(date.getDate()).padStart(2, "0");
+      let hours = String(date.getHours()).padStart(2, "0");
+      let minutes = String(date.getMinutes()).padStart(2, "0");
+      let seconds = String(date.getSeconds()).padStart(2, "0");
+
+      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
+    }
+
     try {
       var tstamp = new Date();
       var logfile = FileUtils.getFile(KEY_PROFILEDIR, [FILE_EXTENSIONS_LOG]);
       var stream = Cc["@mozilla.org/network/file-output-stream;1"].
                    createInstance(Ci.nsIFileOutputStream);
       stream.init(logfile, 0x02 | 0x08 | 0x10, LOGGER_FILE_PERM, 0); // write, create, append
       var writer = Cc["@mozilla.org/intl/converter-output-stream;1"].
                    createInstance(Ci.nsIConverterOutputStream);
       writer.init(stream, "UTF-8", 0, 0x0000);
-      writer.writeString(tstamp.toLocaleFormat("%Y-%m-%d %H:%M:%S ") +
+      writer.writeString(formatTimestamp(tstamp) + " " +
                          message + " at " + stack.sourceName + ":" +
                          stack.lineNumber + "\n");
       writer.close();
     }
     catch (e) { }
   },
 
   warn: function(aStr, aException) {