From 5eed0a61711b591b01145068b27f8bebeea15ba3 Mon Sep 17 00:00:00 2001 From: Antonio Ladeia Date: Thu, 22 Jan 2015 08:10:12 -0300 Subject: [PATCH] Bug 1123372 - Stop using Date.toLocaleFormat() in Places code. r=mak --- toolkit/components/places/PlacesBackups.jsm | 2 +- .../tests/bookmarks/test_1016953-renaming-uncompressed.js | 8 ++++---- .../tests/bookmarks/test_477583_json-backup-in-future.js | 2 +- .../bookmarks/test_818584-discard-duplicate-backups.js | 4 ++-- toolkit/components/places/tests/head_common.js | 4 ++-- .../places/tests/unit/test_utils_backups_create.js | 4 ++-- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/toolkit/components/places/PlacesBackups.jsm b/toolkit/components/places/PlacesBackups.jsm index e1b0b71370b..95c910875b8 100644 --- a/toolkit/components/places/PlacesBackups.jsm +++ b/toolkit/components/places/PlacesBackups.jsm @@ -233,7 +233,7 @@ this.PlacesBackups = { let dateObj = aDateObj || new Date(); // Use YYYY-MM-DD (ISO 8601) as it doesn't contain illegal characters // and makes the alphabetical order of multiple backup files more useful. - return "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + ".json" + + return "bookmarks-" + dateObj.toISOString().substr(0, 10) + ".json" + (aCompress ? "lz4" : ""); }, diff --git a/toolkit/components/places/tests/bookmarks/test_1016953-renaming-uncompressed.js b/toolkit/components/places/tests/bookmarks/test_1016953-renaming-uncompressed.js index 1b0d6802818..bfe7947df6d 100644 --- a/toolkit/components/places/tests/bookmarks/test_1016953-renaming-uncompressed.js +++ b/toolkit/components/places/tests/bookmarks/test_1016953-renaming-uncompressed.js @@ -20,7 +20,7 @@ add_task(function* test_same_date_same_hash() { // Save JSON file in backup folder with hash appended let dateObj = new Date(); - let filename = "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + "_" + + let filename = "bookmarks-" + dateObj.toISOString().substr(0, 10) + "_" + count + "_" + hash + ".json"; let backupFile = OS.Path.join(backupFolder, filename); yield OS.File.move(tempPath, backupFile); @@ -53,7 +53,7 @@ add_task(function* test_same_date_diff_hash() { "bug10169583_bookmarks.json"); let {count, hash} = yield BookmarkJSONUtils.exportToFile(tempPath); let dateObj = new Date(); - let filename = "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + "_" + + let filename = "bookmarks-" + dateObj.toISOString().substr(0, 10) + "_" + count + "_" + "differentHash==" + ".json"; let backupFile = OS.Path.join(backupFolder, filename); yield OS.File.move(tempPath, backupFile); @@ -84,9 +84,9 @@ add_task(function* test_diff_date_same_hash() { let {count, hash} = yield BookmarkJSONUtils.exportToFile(tempPath); let oldDate = new Date(2014, 1, 1); let curDate = new Date(); - let oldFilename = "bookmarks-" + oldDate.toLocaleFormat("%Y-%m-%d") + "_" + + let oldFilename = "bookmarks-" + oldDate.toISOString().substr(0, 10) + "_" + count + "_" + hash + ".json"; - let newFilename = "bookmarks-" + curDate.toLocaleFormat("%Y-%m-%d") + "_" + + let newFilename = "bookmarks-" + curDate.toISOString().substr(0, 10) + "_" + count + "_" + hash + ".json"; let backupFile = OS.Path.join(backupFolder, oldFilename); let newBackupFile = OS.Path.join(backupFolder, newFilename); diff --git a/toolkit/components/places/tests/bookmarks/test_477583_json-backup-in-future.js b/toolkit/components/places/tests/bookmarks/test_477583_json-backup-in-future.js index 5e9b71d26d5..46b88cd3119 100644 --- a/toolkit/components/places/tests/bookmarks/test_477583_json-backup-in-future.js +++ b/toolkit/components/places/tests/bookmarks/test_477583_json-backup-in-future.js @@ -21,7 +21,7 @@ function run_test() { let dateObj = new Date(); dateObj.setYear(dateObj.getFullYear() + 1); let name = PlacesBackups.getFilenameForDate(dateObj); - do_check_eq(name, "bookmarks-" + dateObj.toLocaleFormat("%Y-%m-%d") + ".json"); + do_check_eq(name, "bookmarks-" + dateObj.toISOString().substr(0, 10) + ".json"); files = bookmarksBackupDir.directoryEntries; while (files.hasMoreElements()) { let entry = files.getNext().QueryInterface(Ci.nsIFile); diff --git a/toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js b/toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js index 30efb0e0ebf..8e100fbcb5e 100644 --- a/toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js +++ b/toolkit/components/places/tests/bookmarks/test_818584-discard-duplicate-backups.js @@ -33,7 +33,7 @@ add_task(function() { do_check_eq(backupFiles.length, 1); let matches = OS.Path.basename(backupFiles[0]).match(PlacesBackups.filenamesRegex); - do_check_eq(matches[1], new Date().toLocaleFormat("%Y-%m-%d")); + do_check_eq(matches[1], new Date().toISOString().substr(0, 10)); do_check_eq(matches[2], count); do_check_eq(matches[3], hash); @@ -49,7 +49,7 @@ add_task(function() { recentBackup = yield PlacesBackups.getMostRecentBackup(); do_check_neq(recentBackup, OS.Path.join(backupFolder, oldBackupName)); matches = OS.Path.basename(recentBackup).match(PlacesBackups.filenamesRegex); - do_check_eq(matches[1], new Date().toLocaleFormat("%Y-%m-%d")); + do_check_eq(matches[1], new Date().toISOString().substr(0, 10)); do_check_eq(matches[2], count + 1); do_check_neq(matches[3], hash); diff --git a/toolkit/components/places/tests/head_common.js b/toolkit/components/places/tests/head_common.js index a1b31a8fbb1..8e222775df5 100644 --- a/toolkit/components/places/tests/head_common.js +++ b/toolkit/components/places/tests/head_common.js @@ -402,7 +402,7 @@ function shutdownPlaces(aKeepAliveConnection) const FILENAME_BOOKMARKS_HTML = "bookmarks.html"; const FILENAME_BOOKMARKS_JSON = "bookmarks-" + - (new Date().toLocaleFormat("%Y-%m-%d")) + ".json"; + (new Date().toISOString().substr(0, 10)) + ".json"; /** * Creates a bookmarks.html file in the profile folder from a given source file. @@ -514,7 +514,7 @@ function check_JSON_backup(aIsAutomaticBackup) { let bookmarksBackupDir = gProfD.clone(); bookmarksBackupDir.append("bookmarkbackups"); let files = bookmarksBackupDir.directoryEntries; - let backup_date = new Date().toLocaleFormat("%Y-%m-%d"); + let backup_date = new Date().toISOString().substr(0, 10); while (files.hasMoreElements()) { let entry = files.getNext().QueryInterface(Ci.nsIFile); if (PlacesBackups.filenamesRegex.test(entry.leafName)) { diff --git a/toolkit/components/places/tests/unit/test_utils_backups_create.js b/toolkit/components/places/tests/unit/test_utils_backups_create.js index 98b791cec24..ddbd948fa3e 100644 --- a/toolkit/components/places/tests/unit/test_utils_backups_create.js +++ b/toolkit/components/places/tests/unit/test_utils_backups_create.js @@ -23,7 +23,7 @@ add_task(function () { let randomDate = new Date(dateObj.getFullYear() - 1, Math.floor(12 * Math.random()), Math.floor(28 * Math.random())); - let dateString = randomDate.toLocaleFormat("%Y-%m-%d"); + let dateString = randomDate.toISOString().substr(0, 10); if (dates.indexOf(dateString) == -1) dates.push(dateString); } @@ -49,7 +49,7 @@ add_task(function () { yield PlacesBackups.create(NUMBER_OF_BACKUPS); // Add today's backup. - dates.push(dateObj.toLocaleFormat("%Y-%m-%d")); + dates.push(dateObj.toISOString().substr(0, 10)); // Check backups. We have 11 dates but we the max number is 10 so the // oldest backup should have been removed.