Skip to content

Commit

Permalink
Bug 1313799 - Remove Date.prototype.toLocaleFormat uses in devtools/c…
Browse files Browse the repository at this point in the history
…lient/netmonitor/har. r=Honza

--HG--
extra : rebase_source : 009957fd799ad7dda0022c28a54fe112a95f892d
  • Loading branch information
anba committed Jan 18, 2017
1 parent faa9b11 commit c5d028b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions devtools/client/netmonitor/har/har-exporter.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const HarExporter = {
* 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.
*
Expand Down
15 changes: 12 additions & 3 deletions devtools/client/netmonitor/har/har-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,17 @@ const OPEN_FLAGS = {
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.
*/
Expand Down Expand Up @@ -68,10 +79,8 @@ var HarUtils = {
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, "_", "");

Expand Down
2 changes: 1 addition & 1 deletion devtools/client/preferences/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ 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);
Expand Down

0 comments on commit c5d028b

Please sign in to comment.