Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
tempus-fugit
Advanced tools
Tempus fugit is a Latin expression meaning "time flees", more commonly translated as "time flies". It is frequently used as an inscription on clocks.
This module contains high level api for scheduling jobs and also exposes utilities and classes to help build other more custom / complex scheduling code.
npm install tempus-fugit
The scheduling api can be used to schedule single time or repeating jobs. Repeating jobs revolve around the interval object (see below).
var scheduling = require('tempus-fugit').scheduling;
var futureDate = new Date(....);
var task = function () {};
var job = scheduling.schedule(futureDate, task);
// can cancel
job.cancel();
var scheduling = require('tempus-fugit').scheduling;
var interval = { hour: 1, minute: 5 }; // every hour and 5 minutes
var task = function (job) { job.done(); // this.done() also works };
var job = scheduling.schedule(interval, task);
// can cancel
job.cancel();
var interval = {
millisecond: 1,
second: 2,
hour: 3,
day: 4,
start: Date.now() || new Date() //optional
}
note: the start property is optional, without this property the job will be schedule to the next interval event, calculated since unix epoch time
var AbstractJob = require('tempus-fugit').scheduling.AbstractJob;
var $u = require('util');
$u.inherits(MyJob, AbstractJob);
function MyJob(task, options) {
AbstractJob.call(this, task, options)
}
// must implement
MyJob.prototype._executeImpl = function () {
return setInterval(this._task, 500);
};
// must implement
MyJob.prototype._cancelImpl = function(token) {
return clearInterval(token);
};
// optionally implement, if so, do no pass task argument in constructor
MyJob.prototype._task = function () {
console.log('foo!');
};
var tu = require('tempus-fugit').tu;
var interval = { millisecond: 500, second: 2 };
console.log(tu.intervalObjectToMillis(interval));
will print:
2500
var tu = require('tempus-fugit').tu;
var interval = { millisecond: 1502, second: 2 };
console.log(tu.normalizeIntervalObject(interval));
will print:
{ millisecond: 502, second: 3 }
note: this will modify the original interval object
var tu = require('tempus-fugit').tu;
var interval = { day: 1 };
var n = Date.UTC(2000, 0);
var millis = tu.intervalObjectToMillis(interval);
console.log(tu.intervalCountSinceEpoch(millis, n));
will print:
10957
which is 30 years * 365 day + 7(.5) days from leap years
note: the n argument is optional, if omitted the function will use Date.now() internally
var tu = require('tempus-fugit').tu;
var interval = { day: 1 };
var n = Date.UTC(2000, 0, 1, 0, 30); // Sat Jan 01 2000 00:30:00 GMT
var millis = tu.intervalObjectToMillis(interval);
var nextInterval = tu.nextIntervalEvent(millis, n);
console.log(new Date(nextInterval).toUTCString());
will print:
Sun, 02 Jan 2000 00:00:00 GMT
note: the n argument is optional, if omitted the function will use Date.now() internally
tu.nextSecond(date);
tu.nextMinute(date);
tu.nextHour(date);
tu.nextDate(date);
tu.nextMonth(date);
tu.nextYear(date);
var tf = require('tempus-fugit');
var now = new Date(2013, 11, 25, 23, 23, 59, 123);
var actual = tf.tu.nextSecond(now); // tf.tu === tf.temporalUtil
console.log('closest second:');
console.log(now);
console.log(actual);
will print:
Wed Dec 25 2013 23:23:59 GMT+0200 (Jerusalem Standard Time)
Wed Dec 25 2013 23:24:00 GMT+0200 (Jerusalem Standard Time)
support month and year intervals, calculated correctly
FAQs
A scheduling and time utilities module that doesn't waste your time
The npm package tempus-fugit receives a total of 371 weekly downloads. As such, tempus-fugit popularity was classified as not popular.
We found that tempus-fugit demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.