Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/shared/utils/challenge-listing/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import moment from 'moment';
* @return {Date}
*/
export function phaseEndDate(phase) {
if (phase.actualEndDate) {
return new Date(phase.actualEndDate);
}
// Case 1: phase is still open. take the `scheduledEndDate`
// Case 2: phase is not open but `scheduledStartDate` is a future date.
// This means phase is not yet started. So take the `scheduledEndDate`
Expand All @@ -17,7 +20,7 @@ export function phaseEndDate(phase) {
return new Date(phase.scheduledEndDate);
}
// for other cases, take the `actualEndDate` as phase is already closed
return new Date(phase.scheduledEndDate || phase.actualEndDate);
return new Date(phase.actualEndDate || phase.scheduledEndDate);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
The change from new Date(phase.scheduledEndDate || phase.actualEndDate) to new Date(phase.actualEndDate || phase.scheduledEndDate) alters the logic to prioritize actualEndDate over scheduledEndDate. Ensure this change aligns with the intended business logic, as it may affect how end dates are calculated for phases that are already closed.

}

/**
Expand All @@ -26,12 +29,15 @@ export function phaseEndDate(phase) {
* @return {Date}
*/
export function phaseStartDate(phase) {
if (phase.actualStartDate) {
return new Date(phase.actualStartDate);
}
// Case 1: Phase is not yet started. take the `scheduledStartDate`
if (phase.isOpen !== true && moment(phase.scheduledStartDate).isAfter()) {
return new Date(phase.scheduledStartDate);
}
// For all other cases, take the `actualStartDate` as phase is already started
return new Date(phase.scheduledStartDate || phase.actualStartDate);
return new Date(phase.actualStartDate || phase.scheduledStartDate);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[❗❗ correctness]
Similar to the change in phaseEndDate, the logic now prioritizes actualStartDate over scheduledStartDate. Verify that this change is consistent with the desired behavior for phases that have already started, as it could impact the start date calculations.

}

/**
Expand Down