typescript-dotnet-core
Version:
A the core classes and utilities of a JavaScript-Friendly .NET Based TypeScript Library.
7 lines (6 loc) • 2.06 kB
JavaScript
/*!
* @author electricessence / https://github.com/electricessence/
* Licensing: MIT https://github.com/electricessence/TypeScript.NET-Core/blob/master/LICENSE.md
*/Object.defineProperty(exports,"__esModule",{value:!0});var TimeSpan_1=require("./TimeSpan");function getTimestampMilliseconds(){return(new Date).getTime()}var Stopwatch=function(){function t(){this.reset()}return t.getTimestampMilliseconds=function(){return getTimestampMilliseconds()},Object.defineProperty(t.prototype,"isRunning",{get:function(){return this._isRunning},enumerable:!0,configurable:!0}),t.startNew=function(){var e=new t;return e.start(),e},t.measure=function(e){var t=getTimestampMilliseconds();return e(),new TimeSpan_1.default(getTimestampMilliseconds()-t)},t.prototype.start=function(){var e=this;e._isRunning||(e._startTimeStamp=getTimestampMilliseconds(),e._isRunning=!0)},t.prototype.stop=function(){var e=this;e._isRunning&&(e._elapsed+=e.currentLapMilliseconds,e._isRunning=!1)},t.prototype.reset=function(){var e=this;e._elapsed=0,e._isRunning=!1,e._startTimeStamp=NaN},t.prototype.lap=function(){var e=this;if(e._isRunning){var t=getTimestampMilliseconds(),n=t-e._startTimeStamp;return e._startTimeStamp=t,e._elapsed+=n,new TimeSpan_1.default(n)}return TimeSpan_1.default.zero},Object.defineProperty(t.prototype,"currentLapMilliseconds",{get:function(){return this._isRunning?getTimestampMilliseconds()-this._startTimeStamp:0},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"currentLap",{get:function(){return this._isRunning?new TimeSpan_1.default(this.currentLapMilliseconds):TimeSpan_1.default.zero},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"elapsedMilliseconds",{get:function(){var e=this,t=e._elapsed;return e._isRunning&&(t+=e.currentLapMilliseconds),t},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"elapsed",{get:function(){return new TimeSpan_1.default(this.elapsedMilliseconds)},enumerable:!0,configurable:!0}),t}();exports.default=Stopwatch;
//# sourceMappingURL=Stopwatch.js.map
;