Skip to content

Commit 12c4c0d

Browse files
committed
Date editing fixes
1 parent 8e132d7 commit 12c4c0d

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

src/components/ChallengeEditor/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ import { isBetaMode } from '../../util/cookie'
6868
import MilestoneField from './Milestone-Field'
6969
import DiscussionField from './Discussion-Field'
7070
import CheckpointPrizesField from './CheckpointPrizes-Field'
71+
import { canChangeDuration } from '../../util/phase'
7172

7273
const theme = {
7374
container: styles.modalContainer
@@ -843,8 +844,7 @@ class ChallengeEditor extends Component {
843844
const is2RoundDesignChallenge = isDesignChallenge && is2RoundChallenge
844845

845846
for (let index = 0; index < phases.length; ++index) {
846-
newChallenge.phases[index].isDurationActive =
847-
moment(newChallenge.phases[index]['scheduledEndDate']).isAfter()
847+
newChallenge.phases[index].isDurationActive = canChangeDuration(newChallenge.phases[index])
848848
if ((newChallenge.phases[index].name === 'Submission' && !is2RoundDesignChallenge) || newChallenge.phases[index].name === 'Checkpoint Submission') {
849849
newChallenge.phases[index].isStartTimeActive = true
850850
} else {

src/util/date.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import moment from 'moment'
55
import _ from 'lodash'
66
import 'moment-duration-format'
7+
import { canChangeDuration } from './phase'
78

89
const HOUR_MS = 60 * 60 * 1000
910
const DAY_MS = 24 * HOUR_MS
@@ -120,7 +121,13 @@ export const getRoundFormattedDuration = (duration) => {
120121
export const convertChallengePhaseFromSecondsToHours = (phases) => {
121122
if (phases) {
122123
_.forEach(phases, (p) => {
123-
p.duration = Math.floor(p.duration / minuteToSecond)
124+
if (canChangeDuration(p)) {
125+
p.duration = Math.floor(p.duration / minuteToSecond)
126+
} else {
127+
// use the same duration display as OR, as long as we aren't changing the fields that should be fine.
128+
const duration = moment.duration(moment(p.scheduledEndDate).diff(moment(p.scheduledStartDate)))
129+
p.duration = Math.ceil(duration.asMinutes())
130+
}
124131
})
125132
}
126133
}

src/util/phase.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import moment from 'moment'
2+
3+
export const canChangeDuration = phase => {
4+
if (!phase) {
5+
return false
6+
}
7+
return moment(phase.scheduledEndDate).isAfter()
8+
}

0 commit comments

Comments
 (0)