Skip to content

Commit

Permalink
Moved TimeSpan defaults to the constructor.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpblog committed Apr 19, 2012
1 parent b0c7abb commit a7666bd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 23 deletions.
16 changes: 4 additions & 12 deletions js/atwork.js
Expand Up @@ -72,7 +72,6 @@ function openDB(callback, context) {
req.onsuccess = function(e) {
var db = e.target.result;

console.log('Version: ' + db.version + ', DB_VERSION: ' + DB_VERSION);
if(db.setVersion && db.version != DB_VERSION) {
var verReq = db.setVersion(DB_VERSION);
verReq.onfailure = req.onerror;
Expand Down Expand Up @@ -102,19 +101,13 @@ function extend(parent, proto) {
}

function TimeSpan(ms) {
if(ms) {
this.totalmilliseconds = ms;
this.seconds = Math.floor(ms/1000) % 60;
this.minutes = Math.floor(ms/60000) % 60;
this.hours = Math.floor(ms/3600000) % 24;
}
this.totalmilliseconds = ms || 0;
this.seconds = (ms && Math.floor(ms/1000) % 60) || 0;
this.minutes = (ms && Math.floor(ms/60000) % 60) || 0;
this.hours = (ms && Math.floor(ms/3600000) % 24) || 0;
}

TimeSpan.prototype = {
totalmilliseconds: 0,
seconds: 0,
minutes: 0,
hours: 0,
add: function(other) {
other = typeof other === "number" ? other : other.totalmilliseconds;
var ms = this.totalmilliseconds + other;
Expand All @@ -134,7 +127,6 @@ TimeSpan.prototype = {

return num;
}

};

function Timer() {
Expand Down
15 changes: 4 additions & 11 deletions src/timespan.js
@@ -1,17 +1,11 @@
function TimeSpan(ms) {
if(ms) {
this.totalmilliseconds = ms;
this.seconds = Math.floor(ms/1000) % 60;
this.minutes = Math.floor(ms/60000) % 60;
this.hours = Math.floor(ms/3600000) % 24;
}
this.totalmilliseconds = ms || 0;
this.seconds = (ms && Math.floor(ms/1000) % 60) || 0;
this.minutes = (ms && Math.floor(ms/60000) % 60) || 0;
this.hours = (ms && Math.floor(ms/3600000) % 24) || 0;
}

TimeSpan.prototype = {
totalmilliseconds: 0,
seconds: 0,
minutes: 0,
hours: 0,
add: function(other) {
other = typeof other === "number" ? other : other.totalmilliseconds;
var ms = this.totalmilliseconds + other;
Expand All @@ -31,5 +25,4 @@ TimeSpan.prototype = {

return num;
}

};

0 comments on commit a7666bd

Please sign in to comment.