Comparing version 1.1.0 to 1.2.0
@@ -25,3 +25,3 @@ #!/usr/bin/env node | ||
else if (argv._[0] === 'start') { | ||
var d = argv.d ? new Date(argv.d) : new Date; | ||
var d = argv.date ? new Date(argv.date) : new Date; | ||
var type = argv.type || argv.t; | ||
@@ -36,13 +36,37 @@ var pkey = strftime('time!%F %T', d); | ||
else if (argv._[0] === 'stop') { | ||
var d = argv.d ? new Date(argv.d) : new Date; | ||
var s = db.createReadStream({ | ||
gt: 'time!', lt: 'time!~', | ||
limit: 1, reverse: true | ||
}); | ||
s.once('data', function (row) { | ||
var d = argv.date ? new Date(argv.date) : new Date; | ||
var k = argv.key || argv._[1]; | ||
if (k) { | ||
key = getKey(key); | ||
db.get(key, function (err, value) { | ||
if (err) error(err) | ||
else onrow({ key: key, value: value }) | ||
}); | ||
} | ||
else { | ||
db.createReadStream({ | ||
gt: 'time!', lt: 'time!~', | ||
limit: 1, reverse: true | ||
}).once('data', onrow); | ||
} | ||
function onrow (row) { | ||
if (argv.message) row.value.message = argv.message; | ||
row.value.end = strftime('%F %T', d); | ||
db.put(row.key, row.value, error); | ||
}); | ||
} | ||
} | ||
else if (argv._[0] === 'add' && argv._.length === 3) { | ||
var start = strftime('%F %T', new Date(argv._[1])); | ||
var end = strftime('%F %T', new Date(argv._[2])); | ||
var type = argv.type || argv.t; | ||
var value = { type: type, end: end }; | ||
var pkey = 'time!' + start; | ||
var tkey = 'time-type!' + type + '!' + start; | ||
db.batch([ | ||
{ type: 'put', key: pkey, value: value }, | ||
{ type: 'put', key: tkey, value: 0 } | ||
], error); | ||
} | ||
else if (argv._[0] === 'status') { | ||
@@ -81,8 +105,4 @@ var s = db.createReadStream({ | ||
var hours = rows.reduce(function reducer (acc, row) { | ||
if (!row.value.end) { | ||
console.error("clocked time hasn't ended yet"); | ||
return process.exit(1); | ||
} | ||
var start = new Date(row.key.split('!')[1]); | ||
var end = new Date(row.value.end); | ||
var end = row.value.end ? new Date(row.value.end) : new Date; | ||
var key = strftime('%F', start); | ||
@@ -134,2 +154,3 @@ if (key !== strftime('%F', end)) { | ||
s.pipe(through(function (row) { | ||
if (argv.raw) return console.log(row); | ||
if (row.value.archive && !argv.archive) return; | ||
@@ -214,2 +235,8 @@ if (argv.type && row.value.type !== argv.type) return; | ||
} | ||
else if (argv._[0] === 'insert') { | ||
var key = getKey(argv._[1]); | ||
db.put(key, {}, function (err) { | ||
if (err) return error(err); | ||
}); | ||
} | ||
else if (argv._[0] === 'archive' || argv._[0] === 'unarchive') { | ||
@@ -326,2 +353,3 @@ var value = argv._[0] === 'archive'; | ||
function getKey (x) { | ||
if (!/^\d+$/.test(x)) return 'time!' + x; | ||
return strftime('time!%F %T', new Date(x * 1000)); | ||
@@ -328,0 +356,0 @@ } |
@@ -21,2 +21,5 @@ usage: | ||
clocker add START END {-t TYPE} | ||
Add a hours from START to END as date strings. | ||
clocker get STAMP | ||
@@ -23,0 +26,0 @@ Get the data at STAMP. |
{ | ||
"name": "clocker", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "track project hours", | ||
@@ -5,0 +5,0 @@ "bin": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16828
337
128