From 808541e4624763df1f4c0c9261eec083059dc27c Mon Sep 17 00:00:00 2001 From: David Resseguie Date: Tue, 10 Feb 2015 11:49:07 -0500 Subject: [PATCH] allow user to specify start/restart times Defaults to one hour, reset defaults to original start time unless otherwise specified. --- models/stopwatch.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/models/stopwatch.js b/models/stopwatch.js index 29ace51..3f69bbe 100644 --- a/models/stopwatch.js +++ b/models/stopwatch.js @@ -5,7 +5,7 @@ var util = require('util'), // --------------------------------------------- // Constructor // --------------------------------------------- -function Stopwatch() { +function Stopwatch(startTime) { if(false === (this instanceof Stopwatch)) { return new Stopwatch(); } @@ -13,7 +13,9 @@ function Stopwatch() { this.hour = 3600000; this.minute = 60000; this.second = 1000; - this.time = this.hour; + + this.startTime = startTime || this.hour; + this.time = this.startTime; this.interval = undefined; events.EventEmitter.call(this); @@ -53,9 +55,9 @@ Stopwatch.prototype.stop = function() { } }; -Stopwatch.prototype.reset = function() { +Stopwatch.prototype.reset = function(restartTime) { console.log('Resetting Stopwatch!'); - this.time = this.hour; + this.time = restartTime || this.startTime; this.emit('reset:stopwatch', this.formatTime(this.time)); };