Skip to content

Commit 5ee8bd7

Browse files
authored
Merge pull request #1374 from 52cs/fix-1370
fix issue 1370
2 parents 533530a + 063bb86 commit 5ee8bd7

File tree

2 files changed

+15
-33
lines changed

2 files changed

+15
-33
lines changed

src/components/ChallengeEditor/index.js

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -819,31 +819,21 @@ class ChallengeEditor extends Component {
819819
newChallenge.phases[index]['scheduledStartDate'] = phase.startDate
820820
newChallenge.phases[index]['scheduledEndDate'] = phase.endDate
821821

822-
let lastDate = phase.endDate
823-
for (let phaseIndex = 0; phaseIndex < phases.length; phaseIndex++) {
824-
if (phaseIndex !== index) {
825-
if (moment(phases[phaseIndex]['scheduledStartDate']).isBefore(lastDate)) {
826-
lastDate = moment(lastDate).add('1', 'hour').format('MM/DD/YYYY HH:mm')
827-
828-
if (newChallenge.phases[phaseIndex]['name'] !== 'Submission') {
829-
newChallenge.phases[phaseIndex]['scheduledStartDate'] = lastDate
830-
} else {
831-
newChallenge.phases[phaseIndex]['scheduledStartDate'] = newChallenge.phases[index]['scheduledStartDate']
832-
}
833-
834-
if (moment(phases[phaseIndex]['scheduledEndDate']).isBefore(lastDate)) {
835-
lastDate = moment(lastDate).add('1', 'hour').format('MM/DD/YYYY HH:mm')
836-
newChallenge.phases[phaseIndex]['scheduledEndDate'] = lastDate
837-
}
838-
839-
// if (moment(newChallenge.phases[phaseIndex]['scheduledEndDate']).isAfter(phases[phaseIndex]['scheduledStartDate'])) {
840-
// newChallenge.phases[phaseIndex]['scheduledStartDate'] = moment(newChallenge.phases[phaseIndex]['scheduledEndDate']).subtract('1', 'hour').format('MM/DD/YYYY HH:mm')
841-
// }
842-
843-
newChallenge.phases[phaseIndex]['duration'] =
844-
moment(newChallenge.phases[phaseIndex]['scheduledEndDate']).diff(newChallenge.phases[phaseIndex]['scheduledStartDate'], 'hours')
845-
}
822+
for (let phaseIndex = index + 1; phaseIndex < phases.length; ++phaseIndex) {
823+
if (newChallenge.phases[phaseIndex]['name'] === 'Submission') {
824+
newChallenge.phases[phaseIndex]['scheduledStartDate'] =
825+
newChallenge.phases[phaseIndex - 1]['scheduledStartDate']
826+
newChallenge.phases[phaseIndex]['duration'] =
827+
_.max(newChallenge.phases[phaseIndex - 1]['duration'],
828+
newChallenge.phases[phaseIndex]['duration'])
829+
} else {
830+
newChallenge.phases[phaseIndex]['scheduledStartDate'] =
831+
newChallenge.phases[phaseIndex - 1]['scheduledEndDate']
846832
}
833+
newChallenge.phases[phaseIndex]['scheduledEndDate'] =
834+
moment(newChallenge.phases[phaseIndex]['scheduledStartDate'])
835+
.add(newChallenge.phases[phaseIndex]['duration'], 'hours')
836+
.format('MM/DD/YYYY HH:mm')
847837
}
848838

849839
this.setState({ challenge: newChallenge })

src/components/PhaseInput/index.js

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,8 @@ const PhaseInput = ({ onUpdatePhase, phase, readOnly, phaseIndex, isActive }) =>
4747
}, [startDate, endDate, duration])
4848

4949
const onStartDateChange = (e) => {
50-
const start = moment(e).format()
51-
let end = moment(endDate).format()
52-
53-
if (moment(end).isBefore(moment(start))) {
54-
end = moment(e).add(1, 'day').format(dateFormat)
55-
setEndDate(moment(end).format(dateFormat))
56-
}
57-
5850
setStartDate(moment(e).format(dateFormat))
59-
setDuration(moment(end).diff(start, 'hours'))
51+
setEndDate(moment(e).add(duration, 'hours').format(dateFormat))
6052
}
6153

6254
const onDurationChange = (e) => {

0 commit comments

Comments
 (0)