Skip to content

Instantly share code, notes, and snippets.

@booyaa
Created October 26, 2012 09:49
Show Gist options
  • Save booyaa/3957906 to your computer and use it in GitHub Desktop.
Save booyaa/3957906 to your computer and use it in GitHub Desktop.
Timespan calculator
#!/usr/bin/env node
// Calculators time difference, if you don't provide a 2nd arg it assumes you want the diff
// between 1st arg and the current timestamp
var start, finish, delta, timeParts;
console.log("args: " + process.argv.length);
process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});
if (process.argv.length < 3) {
console.log("please supply start time!");
process.exit(1);
}
timeParts = process.argv[2].split(':');
start = new Date();
start.setHours(timeParts[0]);
start.setMinutes(timeParts[1]);
finish = new Date();
if (process.argv.length == 4) {
timeParts = process.argv[3].split(':');
finish.setHours(timeParts[0]);
finish.setMinutes(timeParts[1]);
}
delta = new Date(finish - start);
console.log("start: %s\nfinish: %s\nspan: %s"
,start.toLocaleTimeString()
,finish.toLocaleTimeString()
,delta.toLocaleTimeString());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment