Bug 493816 - Timestamps need to be saved as string prefs

Internally store .lastSync as a string but keep exposing set/getters as float values. parseFloat takes both strings and numbers and gives a number.

--HG--
extra : rebase_source : b657dd3f732b9f3b3b0ef208ee53e799aa87d2c6
This commit is contained in:
Edward Lee 2009-06-16 17:22:59 -07:00
parent e4a8c23658
commit ce951c538a
2 changed files with 13 additions and 5 deletions

View File

@ -249,18 +249,18 @@ SyncEngine.prototype = {
},
get lastSync() {
return Svc.Prefs.get(this.name + ".lastSync", 0);
return parseFloat(Svc.Prefs.get(this.name + ".lastSync", "0"));
},
set lastSync(value) {
// Reset the pref in-case it's a number instead of a string
Svc.Prefs.reset(this.name + ".lastSync");
if (typeof(value) == "string")
value = parseInt(value);
Svc.Prefs.set(this.name + ".lastSync", value);
// Store the value as a string to keep floating point precision
Svc.Prefs.set(this.name + ".lastSync", value.toString());
},
resetLastSync: function SyncEngine_resetLastSync() {
this._log.debug("Resetting " + this.name + " last sync time");
Svc.Prefs.reset(this.name + ".lastSync");
Svc.Prefs.set(this.name + ".lastSync", 0);
Svc.Prefs.set(this.name + ".lastSync", "0");
},
// Create a new record by querying the store, and add the engine metadata

View File

@ -0,0 +1,8 @@
Cu.import("resource://weave/engines.js");
function run_test() {
// Make sure storing floats for lastSync stay as floats
let engine = new SyncEngine();
engine.lastSync = 123.45;
do_check_eq(engine.lastSync, 123.45);
}