Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

durations

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

durations - npm Package Compare versions

Comparing version 3.1.0 to 3.2.0

lib/duration.js

189

lib/index.js
// Generated by CoffeeScript 1.12.7
(function() {
var Duration, NANOS_PER_DAY, NANOS_PER_HOUR, NANOS_PER_MICRO, NANOS_PER_MILLI, NANOS_PER_MINUTE, NANOS_PER_SECOND, Stopwatch, diffMoments, hrtime, newDuration, newStopwatch, timeOperation, timeOperationAsync;
var duration, stopwatch, timing;
hrtime = require('./hrtime');
duration = require('./duration');
NANOS_PER_MICRO = 1000;
stopwatch = require('./stopwatch');
NANOS_PER_MILLI = NANOS_PER_MICRO * 1000;
timing = require('./timing');
NANOS_PER_SECOND = NANOS_PER_MILLI * 1000;
NANOS_PER_MINUTE = NANOS_PER_SECOND * 60;
NANOS_PER_HOUR = NANOS_PER_MINUTE * 60;
NANOS_PER_DAY = NANOS_PER_HOUR * 24;
Duration = (function() {
function Duration(duration) {
this.negative = duration < 0.0;
this.sign = this.negative ? "-" : "";
this.duration = this.negative ? -duration : duration;
}
Duration.prototype.nanos = function() {
return this.duration;
};
Duration.prototype.micros = function() {
return this.duration / NANOS_PER_MICRO;
};
Duration.prototype.millis = function() {
return this.duration / NANOS_PER_MILLI;
};
Duration.prototype.seconds = function() {
return this.duration / NANOS_PER_SECOND;
};
Duration.prototype.minutes = function() {
return this.duration / NANOS_PER_MINUTE;
};
Duration.prototype.hours = function() {
return this.duration / NANOS_PER_HOUR;
};
Duration.prototype.days = function() {
return this.duration / NANOS_PER_DAY;
};
Duration.prototype.format = function() {
switch (false) {
case !(this.duration >= NANOS_PER_DAY):
return this.sign + Math.floor(this.hours() / 24) + " d, " + Math.floor(this.hours() % 24) + " h";
case !(this.duration >= NANOS_PER_HOUR):
return this.sign + Math.floor(this.minutes() / 60) + " h, " + Math.floor(this.minutes() % 60) + " min";
case !(this.duration >= NANOS_PER_MINUTE):
return this.sign + Math.floor(this.seconds() / 60) + " min, " + Math.floor(this.seconds() % 60) + " s";
case !(this.duration >= NANOS_PER_SECOND):
return this.sign + Math.floor(this.millis() / 1000) + "." + this.zPad(Math.floor(this.millis() % 1000)) + " s";
case !(this.duration >= NANOS_PER_MILLI):
return this.sign + Math.floor(this.micros() / 1000) + "." + this.zPad(Math.floor(this.micros() % 1000)) + " ms";
default:
return this.sign + Math.floor(this.duration / 1000) + "." + this.zPad(Math.floor(this.duration % 1000)) + " us";
}
};
Duration.prototype.toString = function() {
return this.format();
};
Duration.prototype.zPad = function(value) {
switch (false) {
case !(value < 10):
return "00" + value;
case !(value < 100):
return "0" + value;
default:
return "" + value;
}
};
return Duration;
})();
Stopwatch = (function() {
var hrtimeDiffToNanos;
hrtimeDiffToNanos = function(diff) {
return diff[0] * 1e9 + diff[1];
};
function Stopwatch() {
this.reset();
}
Stopwatch.prototype.reset = function() {
this.accumulator = 0;
this.lastTime = null;
return this;
};
Stopwatch.prototype.start = function() {
if (this.lastTime == null) {
this.lastTime = hrtime();
}
return this;
};
Stopwatch.prototype.stop = function() {
if (this.lastTime != null) {
this.accumulator += hrtimeDiffToNanos(hrtime(this.lastTime));
this.lastTime = null;
}
return this;
};
Stopwatch.prototype.duration = function() {
return new Duration(this.elapsedNanos());
};
Stopwatch.prototype.format = function() {
return this.duration().format();
};
Stopwatch.prototype.toString = function() {
return this.format();
};
Stopwatch.prototype.elapsedNanos = function() {
if (this.lastTime != null) {
return this.accumulator + hrtimeDiffToNanos(hrtime(this.lastTime));
} else {
return this.accumulator;
}
};
Stopwatch.prototype.isRunning = function() {
return this.lastTime != null;
};
return Stopwatch;
})();
timeOperation = function(operation) {
var watch;
watch = newStopwatch().start();
operation();
return watch.stop().duration();
};
timeOperationAsync = function(operation, callback) {
var next, watch;
watch = newStopwatch().start();
next = function() {
var duration;
duration = watch.stop().duration();
return callback(duration);
};
return operation(next);
};
newStopwatch = function() {
return new Stopwatch();
};
newDuration = function(nanoseconds) {
return new Duration(nanoseconds);
};
diffMoments = function(momentA, momentB) {
var nanos;
nanos = moment.valueOf() * 1000000 - moment.valueOf() * 1000000;
return newDuration(nanos);
};
module.exports = {
diffMoments: diffMoments,
duration: newDuration,
stopwatch: newStopwatch,
time: timeOperation,
timeAsync: timeOperationAsync
diffMoments: duration.diffMoments,
duration: duration["new"],
stopwatch: stopwatch["new"],
time: timing.time,
timeAsync: timing.timeAsync
};
}).call(this);

@@ -10,3 +10,3 @@ {

],
"version": "3.1.0",
"version": "3.2.0",
"author": "Joel Edwards (https://github.com/joeledwards)",

@@ -13,0 +13,0 @@ "contributors": [

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc