Skip to content

Commit

Permalink
Datetime bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wyt-sonia committed Feb 25, 2020
1 parent ea6aab2 commit a1c3d00
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
6 changes: 3 additions & 3 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
T | 0 | test
T | 0 | 11
T | 0 | 11
T | 0 | CS2101 Reading
T | 0 | CS2103T IP finalize
D | 0 | CS2105 Assignment1 | 23:59 01/03/2020
12 changes: 10 additions & 2 deletions src/main/java/hakunamatata/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,16 @@ public static boolean isInteger(String s) {
* @return The date and time of the input <code>LocalDateTime</code> in String.
*/
public static String getDateTimeString(LocalDateTime dateTime) {
return dateTime.getHour() + ":" + dateTime.getMinute()
+ " " + dateTime.getDayOfMonth() + "/" + dateTime.getMonthValue() + "/" + dateTime.getYear();
String min = dateTime.getMinute() < 10 ? "0" + dateTime.getMinute()
: "" + dateTime.getMinute();
String hour = dateTime.getHour() < 10 ? "0" + dateTime.getHour()
: "" + dateTime.getHour();
String day = dateTime.getDayOfMonth() < 10 ? "0" + dateTime.getDayOfMonth()
: "" + dateTime.getDayOfMonth();
String month = dateTime.getMonthValue() < 10 ? "0" + dateTime.getMonthValue()
: "" + dateTime.getMonthValue();
return hour + ":" + min
+ " " + day + "/" + month + "/" + dateTime.getYear();
}

}
2 changes: 1 addition & 1 deletion src/main/java/hakunamatata/command/DeleteCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public String execute(TaskList tasks, Ui ui, Storage storage) throws HakunaMatat
if (originalListSize == 0) {
throw new HakunaMatataException("emptyList");
}
if (this.index > originalListSize || index < 1) {
if (this.index > originalListSize || this.index < 1) {
throw new HakunaMatataException("deleteWrongIndexRange");
}

Expand Down
6 changes: 4 additions & 2 deletions src/main/java/hakunamatata/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.time.LocalDateTime;

import hakunamatata.Parser;

/**
* Represents a deadline task.
*
Expand Down Expand Up @@ -48,8 +50,8 @@ public LocalDateTime getBy() {
*/
@Override
public String toString() {

return "[D]" + super.toString()
+ " (by: " + by.getHour() + ":" + by.getMinute()
+ " " + by.getDayOfMonth() + "/" + by.getMonthValue() + "/" + by.getYear() + ")";
+ " (by: " + Parser.getDateTimeString(this.by) + ")";
}
}

0 comments on commit a1c3d00

Please sign in to comment.