Skip to content

Instantly share code, notes, and snippets.

@jacobandresen
Created February 3, 2013 20:41
Show Gist options
  • Save jacobandresen/4703578 to your computer and use it in GitHub Desktop.
Save jacobandresen/4703578 to your computer and use it in GitHub Desktop.
timelog
var fs = require('fs');
var TimeLog = function (options) {
function appendToFile (projectId) {
var now = new Date();
var line = now.getHours() +":" + now.getMinutes() + " " + projectId +"\r\n";
fs.appendFile("data.txt", line, function (err) {
if (err) {
console.log(err);
}
});
}
function listProjectsFromDisk (callback) {
fs.readFile("projects.txt", function (err, data) {
if (err) throw err;
console.log(data.toString());
if (callback) {
callback();
}
});
}
return ({
list: function (callback) {
listProjectsFromDisk(callback);
},
start: function (projectId) {
appendToFile (projectId);
},
stop: function () {
appendToFile (-1);
}
});
};
var t = new TimeLog();
t.list( function () {
var prompt = require('prompt');
prompt.get(['id'], function (err, result) {
t.start(result.id);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment