@@ -193,8 +193,15 @@ module.exports = [
193193 }
194194 }
195195
196- if ( entityToUpdate . completionDate && entityToUpdate . completionDate < milestone . startDate ) {
197- const apiErr = new Error ( 'The milestone completionDate should be greater or equal than the startDate.' ) ;
196+ if (
197+ entityToUpdate . completionDate &&
198+ ( entityToUpdate . actualStartDate || milestone . actualStartDate ) &&
199+ moment . utc ( entityToUpdate . completionDate ) . isBefore (
200+ moment . utc ( entityToUpdate . actualStartDate || milestone . actualStartDate ) ,
201+ 'day' ,
202+ )
203+ ) {
204+ const apiErr = new Error ( 'The milestone completionDate should be greater or equal to actualStartDate.' ) ;
198205 apiErr . status = 422 ;
199206 return Promise . reject ( apiErr ) ;
200207 }
@@ -216,7 +223,8 @@ module.exports = [
216223 // if status has changed to be completed, set the compeltionDate if not provided
217224 if ( entityToUpdate . status === MILESTONE_STATUS . COMPLETED ) {
218225 entityToUpdate . completionDate = entityToUpdate . completionDate ? entityToUpdate . completionDate : today ;
219- entityToUpdate . duration = entityToUpdate . completionDate . diff ( entityToUpdate . actualStartDate , 'days' ) + 1 ;
226+ entityToUpdate . duration = moment . utc ( entityToUpdate . completionDate )
227+ . diff ( entityToUpdate . actualStartDate , 'days' ) + 1 ;
220228 }
221229 // if status has changed to be active, set the startDate to today
222230 if ( entityToUpdate . status === MILESTONE_STATUS . ACTIVE ) {
@@ -241,7 +249,8 @@ module.exports = [
241249
242250 // if completionDate has changed
243251 if ( ! statusChanged && completionDateChanged ) {
244- entityToUpdate . duration = entityToUpdate . completionDate . diff ( entityToUpdate . actualStartDate , 'days' ) + 1 ;
252+ entityToUpdate . duration = moment . utc ( entityToUpdate . completionDate )
253+ . diff ( entityToUpdate . actualStartDate , 'days' ) + 1 ;
245254 entityToUpdate . status = MILESTONE_STATUS . COMPLETED ;
246255 }
247256
0 commit comments