@@ -57,6 +57,7 @@ class hasTimes extends Base {
5757 getTimes() {
5858 let times = [],
5959 timeSpent = 0,
60+ totalTimeSpent = 0,
6061 timeUsers = {},
6162 timeFormat = this.config.get('timeFormat', this._type);
6263
@@ -67,24 +68,33 @@ class hasTimes extends Base {
6768 });
6869
6970 let promise = this.parallel(this.notes, (note, done) => {
70- let created = moment(note.created_at), match, subMatch, removeMatch ;
71+ let created = moment(note.created_at), match, subMatch;
7172
72- if (
73- // filter out user notes
73+
74+ if ( //
75+ // filter out user notes
7476 !note.system ||
77+ // filter out notes that are no time things
78+ !(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !removeRegex.exec(note.body)
79+ ) return done();
80+
81+ // create a time string and a time object
82+ let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeSpent, this.config.get('hoursPerDay'))}`);
83+ let time = new Time(timeString, note, this, this.config);
84+
85+ // add to total time spent
86+ totalTimeSpent += time.seconds;
87+
88+ if ( //
7589 // only include times by the configured user
7690 (this.config.get('user') && this.config.get('user') !== note.author.username) ||
7791 // filter out times that are not in the given time frame
78- !(created.isSameOrAfter(moment(this.config.get('from'))) && created.isSameOrBefore(moment(this.config.get('to')))) ||
79- // filter out notes that are no time things
80- !(match = regex.exec(note.body)) && !(subMatch = subRegex.exec(note.body)) && !(removeMatch = removeRegex.exec(note.body))
92+ !(created.isSameOrAfter(moment(this.config.get('from'))) && created.isSameOrBefore(moment(this.config.get('to'))))
8193 ) return done();
8294
8395 if (!timeUsers[note.author.username]) timeUsers[note.author.username] = 0;
8496
85- let timeString = match ? match[1] : (subMatch ? `-${subMatch[1]}` : `-${Time.toHumanReadable(timeSpent, this.config.get('hoursPerDay'))}`);
86- let time = new Time(timeString, note, this, this.config);
87-
97+ // add to time spent & add to user specific time spent
8898 timeSpent += time.seconds;
8999 timeUsers[note.author.username] += time.seconds;
90100
@@ -95,9 +105,20 @@ class hasTimes extends Base {
95105 });
96106
97107 promise = promise.then(() => new Promise(resolve => {
98- if (this.config('_skipDescriptionParsing') || timeSpent === this.data.time_stats.total_time_spent) return resolve();
99-
100- let difference = this.data.time_stats.total_time_spent - timeSpent,
108+ let created = moment(this.data.created_at);
109+
110+ if ( //
111+ // skip if description parsing is disabled
112+ this.config.get('_skipDescriptionParsing') ||
113+ // or the total time matches
114+ totalTimeSpent === this.data.time_stats.total_time_spent ||
115+ // or the user is filtered out
116+ (this.config.get('user') && this.config.get('user') !== this.data.author.username) ||
117+ // or the issue is not within the given time frame
118+ !(created.isSameOrAfter(moment(this.config.get('from'))) && created.isSameOrBefore(moment(this.config.get('to'))))
119+ ) return resolve();
120+
121+ let difference = this.data.time_stats.total_time_spent - totalTimeSpent,
101122 note = Object.assign({noteable_type: this._typeSingular}, this.data);
102123
103124 times.unshift(new Time(Time.toHumanReadable(difference, this.config.get('hoursPerDay')), note, this, this.config));
0 commit comments