Skip to content

Commit

Permalink
store dates as numbers so they can be serialized
Browse files Browse the repository at this point in the history
  • Loading branch information
selaux committed Mar 9, 2014
1 parent 71255fe commit 9c6e98a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/View.js
Expand Up @@ -74,7 +74,7 @@ View = Backbone.View.extend({
return this.compiledTemplate(_.extend({
id: this.module.id,
title: this.module.title,
lastUpdated: new Date()
lastUpdated: new Date().getTime()
}, this.module.attributes, this.getViewData()));
},

Expand Down
5 changes: 2 additions & 3 deletions lib/handlebars/helpers/time.js
@@ -1,13 +1,12 @@
'use strict';

var moment = require('moment'),
_ = require('lodash');
var moment = require('moment');

module.exports = function (time) {
if (typeof time === 'string') {
return time;
}
if (!_.isDate(time)) {
if (typeof time !== 'number') {
return '';
}

Expand Down
5 changes: 3 additions & 2 deletions lib/modules/miners/bfgminer.js
Expand Up @@ -203,12 +203,13 @@ module.exports = Module.extend({
.subtract('hours', elapsedUnits[0])
.subtract('minutes', elapsedUnits[1])
.subtract('seconds', elapsedUnits[2])
.toDate();
.toDate()
.getTime();
}
} else {
hasLastShareTime = pool['Last Share Time'] !== 0;
if (hasLastShareTime) {
lastShareTime = new Date(pool['Last Share Time'] * 1000);
lastShareTime = pool['Last Share Time'] * 1000;
}
}

Expand Down
4 changes: 2 additions & 2 deletions test/specs/lib/handlebars/helpers/timeSpec.js
Expand Up @@ -12,8 +12,8 @@ describe('handlebars/helpers/time', function () {
{ time: undefined, expected: '' },
{ time: {}, expected: '' },
{ time: 'a string', expected: 'a string' },
{ time: moment('2013-02-08 09:30').toDate(), expected: '2013-02-08, 09:30:00' },
{ time: moment('2013-02-08 20:30:11').toDate(), expected: '2013-02-08, 20:30:11' }
{ time: moment('2013-02-08 09:30').toDate().getTime(), expected: '2013-02-08, 09:30:00' },
{ time: moment('2013-02-08 20:30:11').toDate().getTime(), expected: '2013-02-08, 20:30:11' }
].forEach(function (testCase) {
it('should return "' + testCase.expected + '" for "' + testCase.time + '"', function () {
expect(time(testCase.time)).to.equal(testCase.expected);
Expand Down
4 changes: 2 additions & 2 deletions test/specs/lib/modules/miners/bfgminerSpec.js
Expand Up @@ -467,7 +467,7 @@ describe('modules/miners/bfgminer', function () {
priority: 0,
url: 'http://some.url:3030',
active: true,
lastShareTime: new Date(1383752634000)
lastShareTime: 1383752634000
},
{
alive: false,
Expand Down Expand Up @@ -503,7 +503,7 @@ describe('modules/miners/bfgminer', function () {
id: 0,
priority: 0,
url: 'http://some.url:3030',
lastShareTime: moment().startOf('minute').subtract('seconds', 90).toDate(),
lastShareTime: moment().startOf('minute').subtract('seconds', 90).toDate().getTime(),
active: true
},{
alive: true,
Expand Down

0 comments on commit 9c6e98a

Please sign in to comment.