@@ -193,8 +193,15 @@ module.exports = [
193
193
}
194
194
}
195
195
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.' ) ;
198
205
apiErr . status = 422 ;
199
206
return Promise . reject ( apiErr ) ;
200
207
}
@@ -216,7 +223,8 @@ module.exports = [
216
223
// if status has changed to be completed, set the compeltionDate if not provided
217
224
if ( entityToUpdate . status === MILESTONE_STATUS . COMPLETED ) {
218
225
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 ;
220
228
}
221
229
// if status has changed to be active, set the startDate to today
222
230
if ( entityToUpdate . status === MILESTONE_STATUS . ACTIVE ) {
@@ -241,7 +249,8 @@ module.exports = [
241
249
242
250
// if completionDate has changed
243
251
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 ;
245
254
entityToUpdate . status = MILESTONE_STATUS . COMPLETED ;
246
255
}
247
256
0 commit comments