summaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorKimmo Brunfeldt <kimmobrunfeldt@gmail.com>2015-09-22 10:42:19 +0300
committerKimmo Brunfeldt <kimmobrunfeldt@gmail.com>2015-09-22 10:42:19 +0300
commit471cdea43e44d79f3024ff849c85776238144b8f (patch)
tree472fc672664b7ba50163cf9863099896f0d9c189 /index.js
parent97a5212e72ee34bed878627e956058a6eb090625 (diff)
parentbfe03d2531d5a44d83c78af8b77e87f169f4621e (diff)
downloadgit-hours-471cdea43e44d79f3024ff849c85776238144b8f.zip
git-hours-471cdea43e44d79f3024ff849c85776238144b8f.tar.gz
git-hours-471cdea43e44d79f3024ff849c85776238144b8f.tar.bz2
Merge pull request #9 from pieroblunda/pb/since-option
Param --since
Diffstat (limited to 'index.js')
-rwxr-xr-xindex.js56
1 files changed, 53 insertions, 3 deletions
diff --git a/index.js b/index.js
index 6ea3bb2..066d912 100755
--- a/index.js
+++ b/index.js
@@ -15,12 +15,16 @@ var config = {
maxCommitDiffInMinutes: 2 * 60,
// How many minutes should be added for the first commit of coding session
- firstCommitAdditionInMinutes: 2 * 60
+ firstCommitAdditionInMinutes: 2 * 60,
+
+ //Since data
+ since: 'always'
};
function main() {
parseArgs();
config = mergeDefaultsWithArgs(config);
+ parseSinceDate(config);
commits('.').then(function(commits) {
var commitsByEmail = _.groupBy(commits, function(commit) {
@@ -79,6 +83,11 @@ function parseArgs() {
'-a, --first-commit-add [first-commit-add]',
'how many minutes first commit of session should add to total. Default: ' + config.firstCommitAdditionInMinutes,
int
+ )
+ .option(
+ '-s, --since [since-certain-date]',
+ 'Analyze data since certain date. [always|yesterday|tonight|lastweek|yyyy-mm-dd] Default: ' + config.since,
+ String
);
program.on('--help', function() {
@@ -96,6 +105,14 @@ function parseArgs() {
console.log('');
console.log(' $ git hours --first-commit-add 300');
console.log('');
+ console.log(' - Estimate hours work in repository since yesterday');
+ console.log('');
+ console.log(' $ git hours --since yesterday');
+ console.log('');
+ console.log(' - Estimate hours work in repository since 2015-01-31');
+ console.log('');
+ console.log(' $ git hours --since 2015-01-31');
+ console.log('');
console.log(' For more details, visit https://github.com/kimmobrunfeldt/git-hours');
console.log('');
});
@@ -103,11 +120,42 @@ function parseArgs() {
program.parse(process.argv);
}
+function parseSinceDate(options){
+ var justNow, thisPeriod, paramDate;
+ switch(options.since){
+ case 'tonight':
+ justNow = new Date();
+ thisPeriod = new Date(justNow.getFullYear(), justNow.getMonth(), justNow.getUTCDate());
+ config.since = thisPeriod;
+ break;
+ case 'yesterday':
+ justNow = new Date();
+ thisPeriod = new Date(justNow.getFullYear(), justNow.getMonth(), justNow.getUTCDate()-1);
+ config.since = thisPeriod;
+ break;
+ case 'lastweek':
+ justNow = new Date();
+ thisPeriod = new Date(justNow.getFullYear(), justNow.getMonth(), justNow.getUTCDate()-7);
+ config.since = thisPeriod;
+ break;
+ case 'always':
+ break;
+ default:
+ paramDate = new Date(String(config.since));
+ if(paramDate === undefined){
+ config.since = 'always';
+ }else{
+ config.since = paramDate;
+ }
+ }
+}
+
function mergeDefaultsWithArgs(config) {
return {
range: program.range,
maxCommitDiffInMinutes: program.maxCommitDiff || config.maxCommitDiffInMinutes,
- firstCommitAdditionInMinutes: program.firstCommitAdd || config.firstCommitAdditionInMinutes
+ firstCommitAdditionInMinutes: program.firstCommitAdd || config.firstCommitAdditionInMinutes,
+ since: program.since || config.since
};
}
@@ -227,7 +275,9 @@ function getBranchCommits(branchLatestCommit) {
author: author
};
- commits.push(commitData);
+ if(commitData.date > config.since || config.since === 'always'){
+ commits.push(commitData);
+ }
});
history.on('end', function() {