@@ -6,6 +6,7 @@ const Time = require('./time');
66
77const regex = / a d d e d ( .* ) o f t i m e s p e n t / i;
88const subRegex = / s u b t r a c t e d ( .* ) o f t i m e s p e n t / i;
9+ const removeRegex = / R e m o v e d t i m e s p e n t / i;
910
1011/**
1112 * base model for models that have times
@@ -53,8 +54,14 @@ class hasTimes extends Base {
5354 let timeSpent = 0 ;
5455 let timeUsers = { } ;
5556
57+ // sort by created at
58+ this . notes . sort ( ( a , b ) => {
59+ if ( a . created_at === b . created_at ) return 0 ;
60+ return moment ( a . created_at ) . isBefore ( b . created_at ) ? - 1 : 1 ;
61+ } ) ;
62+
5663 let promise = this . parallel ( this . notes , ( note , done ) => {
57- let created = moment ( note . created_at ) , match , subMatch ;
64+ let created = moment ( note . created_at ) , match , subMatch , removeMatch ;
5865
5966 if (
6067 // filter out user notes
@@ -64,11 +71,13 @@ class hasTimes extends Base {
6471 // filter out times that are not in the given time frame
6572 ! ( created . isSameOrAfter ( this . config . get ( 'from' ) ) && created . isSameOrBefore ( this . config . get ( 'to' ) ) ) ||
6673 // filter out notes that are no time things
67- ! ( match = regex . exec ( note . body ) ) && ! ( subMatch = subRegex . exec ( note . body ) )
74+ ! ( match = regex . exec ( note . body ) ) && ! ( subMatch = subRegex . exec ( note . body ) ) && ! ( removeMatch = removeRegex . exec ( note . body ) )
6875 ) return done ( ) ;
6976
7077 if ( ! timeUsers [ note . author . username ] ) timeUsers [ note . author . username ] = 0 ;
71- let time = new Time ( match ? match [ 1 ] : `-${ subMatch [ 1 ] } ` , note , this , this . config ) ;
78+
79+ let timeString = match ? match [ 1 ] : ( subMatch ? `-${ subMatch [ 1 ] } ` : `-${ Time . toHumanReadable ( timeSpent , this . config . get ( 'hoursPerDay' ) ) } ` ) ;
80+ let time = new Time ( timeString , note , this , this . config ) ;
7281
7382 timeSpent += time . seconds ;
7483 timeUsers [ note . author . username ] += time . seconds ;
0 commit comments