Bug 1123372 - Stop using Date.toLocaleFormat() in Places code. r=mak

This commit is contained in:
Antonio Ladeia 2015-01-22 08:10:12 -03:00
parent fa7b51a9fe
commit 5eed0a6171
6 changed files with 12 additions and 12 deletions

View File

@ -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" : "");
},

View File

@ -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);

View File

@ -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);

View File

@ -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);

View File

@ -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)) {

View File

@ -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.