Bug 1313799 - Remove Date.prototype.toLocaleFormat uses in devtools/client/netmonitor/har. r=Honza
authorAndré Bargull <andre.bargull@gmail.com>
Wed, 18 Jan 2017 03:02:41 -0800
changeset 377357 dc3f3764b1d56948225395e8a6d76ff275f261b4
parent 377356 338d4cec4ffd40a0b95b41c24ad57602b9032b27
child 377358 3f63b9d012c00b125b56be00619ecef7979cf37b
push id1419
push userjlund@mozilla.com
push dateMon, 10 Apr 2017 20:44:07 +0000
treeherdermozilla-release@5e6801b73ef6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersHonza
bugs1313799
milestone53.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 1313799 - Remove Date.prototype.toLocaleFormat uses in devtools/client/netmonitor/har. r=Honza
devtools/client/netmonitor/har/har-exporter.js
devtools/client/netmonitor/har/har-utils.js
devtools/client/preferences/devtools.js
--- a/devtools/client/netmonitor/har/har-exporter.js
+++ b/devtools/client/netmonitor/har/har-exporter.js
@@ -54,18 +54,18 @@ const HarExporter = {
    *
    * - jsonpCallback {String}: Default name of JSONP callback (used for
    *   HARP format).
    *
    * - compress {Boolean}: If set to true the final HAR file is zipped.
    *   This represents great disk-space optimization.
    *
    * - defaultFileName {String}: Default name of the target HAR file.
-   *   The default file name supports formatters, see:
-   *   https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleFormat
+   *   The default file name supports the format specifier %date to output the
+   *   current date/time.
    *
    * - defaultLogDir {String}: Default log directory for automated logs.
    *
    * - id {String}: ID of the page (used in the HAR file).
    *
    * - title {String}: Title of the page (used in the HAR file).
    *
    * - forceExport {Boolean}: The result HAR file is created even if
--- a/devtools/client/netmonitor/har/har-utils.js
+++ b/devtools/client/netmonitor/har/har-utils.js
@@ -32,16 +32,27 @@ const OPEN_FLAGS = {
   RDONLY: parseInt("0x01", 16),
   WRONLY: parseInt("0x02", 16),
   CREATE_FILE: parseInt("0x08", 16),
   APPEND: parseInt("0x10", 16),
   TRUNCATE: parseInt("0x20", 16),
   EXCL: parseInt("0x80", 16)
 };
 
+function formatDate(date) {
+  let year = String(date.getFullYear() % 100).padStart(2, "0");
+  let month = String(date.getMonth() + 1).padStart(2, "0");
+  let day = String(date.getDate()).padStart(2, "0");
+  let hour = 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} ${hour}-${minutes}-${seconds}`;
+}
+
 /**
  * Helper API for HAR export features.
  */
 var HarUtils = {
   /**
    * Open File Save As dialog and let the user pick the proper file
    * location for generated HAR log.
    */
@@ -63,20 +74,18 @@ var HarUtils = {
     }
 
     return null;
   },
 
   getHarFileName: function (defaultFileName, jsonp, compress) {
     let extension = jsonp ? ".harp" : ".har";
 
-    // Read more about toLocaleFormat & format string.
-    // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toLocaleFormat
     let now = new Date();
-    let name = now.toLocaleFormat(defaultFileName);
+    let name = defaultFileName.replace(/%date/g, formatDate(now));
     name = name.replace(/\:/gm, "-", "");
     name = name.replace(/\//gm, "_", "");
 
     let fileName = name + extension;
 
     // Default file extension is zip if compressing is on.
     if (compress) {
       fileName += ".zip";
--- a/devtools/client/preferences/devtools.js
+++ b/devtools/client/preferences/devtools.js
@@ -171,17 +171,17 @@ pref("devtools.netmonitor.enabled", true
 
 // The default Network Monitor UI settings
 pref("devtools.netmonitor.panes-network-details-width", 550);
 pref("devtools.netmonitor.panes-network-details-height", 450);
 pref("devtools.netmonitor.filters", "[\"all\"]");
 
 // The default Network monitor HAR export setting
 pref("devtools.netmonitor.har.defaultLogDir", "");
-pref("devtools.netmonitor.har.defaultFileName", "Archive %y-%m-%d %H-%M-%S");
+pref("devtools.netmonitor.har.defaultFileName", "Archive %date");
 pref("devtools.netmonitor.har.jsonp", false);
 pref("devtools.netmonitor.har.jsonpCallback", "");
 pref("devtools.netmonitor.har.includeResponseBodies", true);
 pref("devtools.netmonitor.har.compress", false);
 pref("devtools.netmonitor.har.forceExport", false);
 pref("devtools.netmonitor.har.pageLoadedTimeout", 1500);
 pref("devtools.netmonitor.har.enableAutoExportToFile", false);