@@ -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 (?: a 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 (?: a t ( .* ) ) ? / i;
9+ const delRegex = / d e l e t e d ( .* ) o f s p e n t t i m e (?: f r o m ( .* ) ) ? / i;
910const removeRegex = / R e m o v e d t i m e s p e n t / i;
1011
1112/**
@@ -72,23 +73,43 @@ class hasTimes extends Base {
7273 } ) ;
7374
7475 let promise = this . parallel ( this . notes , ( note , done ) => {
75- let created = moment ( note . created_at ) , match , subMatch ;
76+ let created = moment ( note . created_at ) , match , subMatch , delMatch ;
7677
7778 if ( //
7879 // filter out user notes
7980 ! note . system ||
8081 // filter out notes that are no time things
81- ! ( match = regex . exec ( note . body ) ) && ! ( subMatch = subRegex . exec ( note . body ) ) && ! removeRegex . exec ( note . body )
82+ ! ( match = regex . exec ( note . body ) ) && ! ( subMatch = subRegex . exec ( note . body ) ) && ! removeRegex . exec ( note . body ) && ! ( delMatch = delRegex . exec ( note . body ) )
8283 ) return done ( ) ;
8384
8485 // change created date when explicitly defined
8586 if ( match && match [ 2 ] ) created = moment ( match [ 2 ] ) ;
8687 if ( subMatch && subMatch [ 2 ] ) created = moment ( subMatch [ 2 ] ) ;
88+ if ( delMatch && delMatch [ 2 ] ) created = moment ( delMatch [ 2 ] ) ;
8789
8890 // create a time string and a time object
89- let timeString = match ? match [ 1 ] : ( subMatch ? `-${ subMatch [ 1 ] } ` : `-${ Time . toHumanReadable ( timeSpent ) } ` ) ;
91+ let timeString = null ;
92+ let multiplier = 1 ;
93+ if ( match ) {
94+ timeString = match [ 1 ] ;
95+ }
96+ else if ( subMatch ) {
97+ timeString = subMatch [ 1 ] ;
98+ multiplier = - 1 ;
99+ }
100+ else if ( delMatch ) {
101+ timeString = delMatch [ 1 ] ;
102+ multiplier = - 1 ; ;
103+ }
104+ else {
105+ // Removed time spent -> remove all
106+ timeString = Time . toHumanReadable ( timeSpent ) ;
107+ multiplier = - 1 ;
108+ }
109+
90110 let time = new Time ( null , created , note , this , this . config ) ;
91- time . seconds = Time . parse ( timeString , 8 , 5 , 4 ) ;
111+ time . seconds = Time . parse ( timeString , 8 , 5 , 4 ) * multiplier ;
112+
92113
93114 // add to total time spent
94115 totalTimeSpent += time . seconds ;
0 commit comments