Skip to content
This repository was archived by the owner on Jun 3, 2025. It is now read-only.

Commit b552046

Browse files
author
Aleksi Salmela
committed
Fix deadline printing.
1 parent 214f880 commit b552046

4 files changed

Lines changed: 13 additions & 13 deletions

File tree

scripts/stub.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ EOM
103103
PROFILE_FILE=$(tmc_detect_profile)
104104

105105
# get the aliases
106+
#TODO remove this and use global variables
106107
set +euo pipefail
107108
source $PROFILE_FILE
108109
set -euo pipefail

src/main/java/fi/helsinki/cs/tmc/cli/backend/CourseInfo.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ public Exercise getExercise(String name) {
8787
return null;
8888
}
8989

90+
public static String getExerciseDeadline(Exercise exercise) {
91+
if (exercise.getDeadline() == null) {
92+
return "none";
93+
}
94+
return exercise.getDeadlineDate().toString();
95+
}
96+
9097
public void setExercises(List<Exercise> exercises) {
9198
this.course.setExercises(exercises);
9299
}

src/main/java/fi/helsinki/cs/tmc/cli/command/InfoCommand.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ private void printExercise(Exercise exercise) {
184184

185185
private void printExerciseShort(Exercise exercise) {
186186
io.println("Exercise: " + exercise.getName());
187-
io.println("Deadline: " + exercise.getDeadlineDate());
187+
if (exercise.getDeadline() != null) {
188+
io.println("Deadline: " + exercise.getDeadlineDate());
189+
}
188190

189191
if (exercise.hasDeadlinePassed() && !exercise.isCompleted()) {
190192
io.println(ColorUtil.colorString("deadline passed", Color.PURPLE));
@@ -234,7 +236,7 @@ private void printExerciseFull(Exercise exercise) {
234236
io.println(" Exercise id: " + exercise.getId());
235237
io.println(" Is locked: " + exercise.isLocked());
236238
io.println(" Deadline description: " + exercise.getDeadlineDescription());
237-
io.println(" Deadline: " + exercise.getDeadlineDate());
239+
io.println(" Deadline: " + CourseInfo.getExerciseDeadline(exercise));
238240
io.println(" Deadline passed: " + exercise.hasDeadlinePassed());
239241
io.println(" Is returnable: " + exercise.isReturnable());
240242
io.println(" Review required: " + exercise.requiresReview());

src/main/java/fi/helsinki/cs/tmc/cli/command/ListExercisesCommand.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ private String getExercisesAsString(String courseName, List<Exercise> exercises)
136136
String prevDeadline = "";
137137

138138
for (Exercise exercise : exercises) {
139-
String deadline = getDeadline(exercise);
139+
String deadline = CourseInfo.getExerciseDeadline(exercise);
140140
if (!deadline.equals(prevDeadline)) {
141141
sb.append("\nDeadline: " + deadline + "\n");
142142
prevDeadline = deadline;
@@ -146,16 +146,6 @@ private String getExercisesAsString(String courseName, List<Exercise> exercises)
146146
return sb.toString();
147147
}
148148

149-
//TODO duplicate code existed in info command!!!!!!!
150-
private String getDeadline(Exercise exercise) {
151-
String deadline = exercise.getDeadline();
152-
if (deadline == null) {
153-
return "not available";
154-
}
155-
deadline = deadline.substring(0, 19);
156-
return deadline.replace("T", " at ");
157-
}
158-
159149
private String getExerciseStatus(Exercise exercise) {
160150
// Check the exercise status in order of flag importance, for example there's
161151
// no need to check if deadline has passed if the exercise has been submitted

0 commit comments

Comments
 (0)