Skip to content

Commit

Permalink
Added beginDate property Session object.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewpblog committed Feb 16, 2012
1 parent 35cb417 commit 161a67a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
14 changes: 12 additions & 2 deletions js/atwork.js
Expand Up @@ -4,7 +4,7 @@
'use strict';
var OS_NAME = 'sessions',
DB_NAME = 'atwork',
DB_VERSION = 1;
DB_VERSION = 1.1;

window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
Expand Down Expand Up @@ -203,6 +203,7 @@ Session.getAll = function(callback) {
Session.create = function(obj) {
var session = new Session();
session.id = obj.id;
session.beginDate = obj.beginDate;
obj.times.forEach(function(timeData) {
var time = new TimeSpan(timeData.totalmilliseconds);
session.times.push(time);
Expand Down Expand Up @@ -274,7 +275,9 @@ var WorkPage = {
this.timer = new Timer();

localStorage['enabled'] = false;
localStorage['running'] = false;
localStorage['time'] = null;
delete localStorage['begin'];

this.elem.textContent = null;
},
Expand Down Expand Up @@ -321,6 +324,11 @@ var WorkPage = {
saveSession: function() {
var time = this.timer.time;
var session = new Session([time]);
var gt = parseInt(localStorage['begin']);
var begin = new Date();
begin.setTime(gt);
session.beginDate = begin;

session.save();
SessionList.add(session);
this.reset();
Expand All @@ -330,6 +338,8 @@ var WorkPage = {
localStorage['enabled'] = this.timer.running;
var strTime = JSON.stringify(ts);
localStorage['time'] = strTime;
localStorage['begin'] = localStorage['begin']
|| (new Date()).getTime();
},

startPressed: function() {
Expand Down Expand Up @@ -385,7 +395,7 @@ var WorkPage = {
var ts = this.timer.elapsed;

this.elem.textContent = ts.toString();
this.saveState(ts);
this.saveState(ts, new Date());
}
};

Expand Down
2 changes: 1 addition & 1 deletion src/database.js
@@ -1,6 +1,6 @@
var OS_NAME = 'sessions',
DB_NAME = 'atwork',
DB_VERSION = 1;
DB_VERSION = 1.1;

window.indexedDB = window.indexedDB || window.webkitIndexedDB || window.mozIndexedDB || window.msIndexedDB;
window.IDBTransaction = window.IDBTransaction || window.webkitIDBTransaction;
Expand Down
1 change: 1 addition & 0 deletions src/session.js
Expand Up @@ -80,6 +80,7 @@ Session.getAll = function(callback) {
Session.create = function(obj) {
var session = new Session();
session.id = obj.id;
session.beginDate = obj.beginDate;
obj.times.forEach(function(timeData) {
var time = new TimeSpan(timeData.totalmilliseconds);
session.times.push(time);
Expand Down
11 changes: 10 additions & 1 deletion src/work_page.js
Expand Up @@ -26,7 +26,9 @@ var WorkPage = {
this.timer = new Timer();

localStorage['enabled'] = false;
localStorage['running'] = false;
localStorage['time'] = null;
delete localStorage['begin'];

this.elem.textContent = null;
},
Expand Down Expand Up @@ -73,6 +75,11 @@ var WorkPage = {
saveSession: function() {
var time = this.timer.time;
var session = new Session([time]);
var gt = parseInt(localStorage['begin']);
var begin = new Date();
begin.setTime(gt);
session.beginDate = begin;

session.save();
SessionList.add(session);
this.reset();
Expand All @@ -82,6 +89,8 @@ var WorkPage = {
localStorage['enabled'] = this.timer.running;
var strTime = JSON.stringify(ts);
localStorage['time'] = strTime;
localStorage['begin'] = localStorage['begin']
|| (new Date()).getTime();
},

startPressed: function() {
Expand Down Expand Up @@ -137,6 +146,6 @@ var WorkPage = {
var ts = this.timer.elapsed;

this.elem.textContent = ts.toString();
this.saveState(ts);
this.saveState(ts, new Date());
}
};

0 comments on commit 161a67a

Please sign in to comment.