Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[nicljr] iP #369

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
556af3f
Add Gradle support
May 24, 2020
df77119
no message
nicljr Jan 23, 2023
d6b8764
Duke Level 2: Add, List
nicljr Jan 23, 2023
c910988
Duke Level 3 Mark As Done
nicljr Jan 23, 2023
f2837d0
Duke Level 4: ToDo, Deadline, Event
nicljr Jan 23, 2023
c26dc5f
Duke: A-TextUiTesting
nicljr Jan 25, 2023
7fccd03
Duke Level-5: Handle Errors
nicljr Jan 26, 2023
a7f039d
Duke Level 6: Delete
nicljr Jan 26, 2023
326442a
Duke Level-7: Save and Load
nicljr Jan 31, 2023
722efb2
Duke Level 8: Dates and Times
nicljr Jan 31, 2023
b808016
Duke A-MoreOOP: Use More OOP
nicljr Jan 31, 2023
a29957d
no message
nicljr Jan 31, 2023
8adc44b
no message
nicljr Jan 31, 2023
a40eea4
Merge remote-tracking branch 'origin/add-gradle-support'
nicljr Jan 31, 2023
1d74e99
Duke: A-Packages
nicljr Jan 31, 2023
8836d32
Updated Commands and TaskList
nicljr Jan 31, 2023
45f7698
Fixed Dates and Times
nicljr Feb 1, 2023
45d6446
Duke A-JUnit: Testing behaviour of Code + Updated Printing Methods fo…
nicljr Feb 2, 2023
463ddac
Duke: A-JavaDoc
nicljr Feb 2, 2023
f4d424f
Duke: A-CodingStandard
nicljr Feb 2, 2023
fc0bd0a
Duke Level-9: Find Command
nicljr Feb 4, 2023
cf14b0c
Duke Level 10: Completeing JavaFX Tutorial
nicljr Feb 6, 2023
27fff36
Duke Level 10: GUI/ Updated Command and UI
nicljr Feb 7, 2023
0b1488d
Duke A-CheckStyle
nicljr Feb 7, 2023
15154a2
Invalid events are accepted by Duke, where the end date is earlier th…
nicljr Feb 7, 2023
35810a9
Duke A-Assertions
nicljr Feb 7, 2023
09b4513
Revert "Duke A-Assertions"
nicljr Feb 7, 2023
d6156b2
Duke A-Assertions
nicljr Feb 7, 2023
19c9546
Merge pull request #1 from nicljr/A-Assertions
nicljr Feb 7, 2023
be2ea3e
Duke A-Jar: JAR File created for v0.2 upgraded from v0.1
nicljr Feb 11, 2023
00bdbb8
Duke Level-9: Making Find more specific
nicljr Feb 11, 2023
3bceb3a
Revert "Duke Level-9: Making Find more specific"
nicljr Feb 11, 2023
86b6388
Revert "Revert "Duke Level-9: Making Find more specific""
nicljr Feb 11, 2023
c13783f
A-CodingStandard: Fix Coding Standards
nicljr Feb 11, 2023
45b8a2d
Merge pull request #3 from nicljr/A-CodeQuality
nicljr Feb 11, 2023
dc82fb8
Duke C-Statistics: Provided Statistics on the added tasks within the …
nicljr Feb 12, 2023
e2d914c
Update README.md
nicljr Feb 14, 2023
489aa58
Update README.md
nicljr Feb 14, 2023
1532784
JavaDocs and CheckStyle
nicljr Feb 14, 2023
9684d05
Merge branch 'master' of https://github.com/nicljr/ip
nicljr Feb 14, 2023
8cb19eb
Duke A-UserGuide
nicljr Feb 14, 2023
4363e12
JAR-Release Updates
nicljr Feb 17, 2023
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
1 change: 0 additions & 1 deletion DukeData/tasks.txt
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
T|0|borrow book
29 changes: 23 additions & 6 deletions src/main/java/duke/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import duke.command.*;

import java.time.LocalDate;
import java.sql.Date;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;

public class Parser {

Choose a reason for hiding this comment

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

Should Parser have a descriptive header comment?


public static DateTimeFormatter strFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm");
public static DateTimeFormatter ldtFormatter = DateTimeFormatter.ofPattern("MMM dd yyyy HHmm");


public static Integer stringToInt(String index) {
return Integer.parseInt(index);
}
Expand All @@ -29,12 +34,24 @@ public static Command stringToCommand(String command) {
}
}

public static LocalDate stringToDate(String duration) {
LocalDate localDate = LocalDate.parse(duration);
return localDate;
public static String[] deadlineSplit(String deadline) {
return deadline.split(" ", 2);
}

public static String[] eventSplit(String event) {
return event.split(" ", 6);
}

public static LocalDateTime stringToDateTime(String duration) {
LocalDateTime localDateTime = LocalDateTime.parse(duration, strFormatter);
return localDateTime;
}

public static String dateTimeToString(LocalDateTime localDateTime) {

Choose a reason for hiding this comment

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

Should methods such as deadlineSplit be named something like splitDeadlineIntoStringArray to better follow the convention of naming methods using verbs?

return localDateTime.format(ldtFormatter);
}

public static String dateToString(LocalDate localDate) {
return localDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy"));
public static String dateTimeSaving(LocalDateTime localDateTime) {
return localDateTime.format(strFormatter);
}
}
1 change: 1 addition & 0 deletions src/main/java/duke/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void loadTasks(TaskList taskList) throws IOException {
break;
case ("E"):
curr = new Events(text[2], text[3], text[4]);
break;
default:
System.out.println("Error while Loading up the file");
break;
Expand Down
21 changes: 13 additions & 8 deletions src/main/java/duke/TaskAssigner.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,33 +45,38 @@ public Task assignToDo(String command) {
public Task assignDeadline(String command) throws DukeException {
String[] splitTiming = command.split("/by ");
if (splitTiming.length != 2) {
throw new DukeException("Improper Deadline Format! deadline {desc} /by {date}\n");
throw new DukeException("Improper Deadline Format! deadline {desc} /by yyyy-mm-dd hhmm\n");
}

try {
int d_index = command.indexOf("/by ") + 4;
String deadline = command.substring(d_index);
System.out.println(deadline);
String updated_deadline = TimeChecker.updateTime(deadline);
String d_desc = command.substring(9, d_index - 4);
return new Deadline(d_desc, deadline);
return new Deadline(d_desc, updated_deadline);

Choose a reason for hiding this comment

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

Might want to consider changing updated_deadline to updatedDeadline to adhere to the Java coding standard of naming variables in camelCase. I noticed that you used snake_case instead of camelCase in several other areas of your code as well. Might I suggest using checkStyle to detect such cases which could save you a lot of time instead of finding them manually.

} catch (DateTimeParseException e) {
throw new DukeException("Date Incorrect Time Format! Follow: yyyy-mm-dd\n");
throw new DukeException("Improper Deadline Format! deadline {desc} /by yyyy-mm-dd hhmm\n");
}
}

public Task assignEvent(String command) throws DukeException {
String[] splitTimings = command.split("/from | /to");
String[] splitTimings = command.split("/from | /to ");

Choose a reason for hiding this comment

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

May I clarify the intention behind the naming of this variable? Perhaps another name could be choosen to convey the message that the variable is an array of strings representing time (ie. timestampsAsString)

if (splitTimings.length != 3) {
throw new DukeException("Improper Event Format! Event {desc} /from {date} /to {date}\n");
throw new DukeException("Improper Event Format! Follow:\n" +
"event {desc} /from yyyy-mm-dd hhmm /to yyyy-mm-dd hhmm\n");
}
try {
int s_index = command.indexOf("/from") + 6;
int e_index = command.indexOf("/to") + 4;
String start_date = command.substring(s_index, e_index - 5);
String end_date = command.substring(e_index);
String start_date = TimeChecker.updateTime(command.substring(s_index, e_index - 5));
String end_date = TimeChecker.updateTime(command.substring(e_index));
String e_desc = command.substring(6, s_index - 6);
return new Events(e_desc, start_date, end_date);
} catch (DateTimeParseException e) {
throw new DukeException("Date Incorrect Format! Follow: yyyy-mm-dd\n");
throw new DukeException("Improper Event Format! Follow:\n" +
"event {desc} /from yyyy-mm-dd hhmm /to yyyy-mm-dd hhmm\n");

}
}
}
20 changes: 20 additions & 0 deletions src/main/java/duke/TimeChecker.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package duke;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;

public class TimeChecker {

public static String DEFAULT_TIME = "2359";
private static DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("HHmm");

public static String updateTime(String timeline) {
String[] split = timeline.split(" ");
if (split.length == 2) {
return timeline;
} else {
return timeline + " " + DEFAULT_TIME;
}
}
}
23 changes: 17 additions & 6 deletions src/main/java/duke/tasks/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,38 @@

import duke.Parser;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class Deadline extends Task {
protected LocalDate by;

static protected String DEFAULT_TIME = "2359";
protected LocalDateTime by;

Choose a reason for hiding this comment

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

Not sure if others will understand what the by variable represents on first look! Perhaps you could consider renaming it to dateBy so as to convey to others that it is a date!


public Deadline(String description, String by) {
super(description);
this.by = Parser.stringToDate(by);
super(description);
this.by = Parser.stringToDateTime(by);
}

@Override
public String getStatusIcon() {
return "[D]" + super.getStatusIcon();
}

public String getBy() {
return Parser.dateTimeToString(by);
}

@Override
public String getDescription() {
return super.getDescription() + " (by: " + this.by + ")";
return super.getDescription() + " (by: " + this.getBy() + ")";
}

public String parseBySaving() {
return Parser.dateTimeSaving(by);
}

@Override
public String saveString() {
return String.format("D|%s|%s|%s", super.saveString(), super.description, this.by);
return String.format("D|%s|%s|%s", super.saveString(), super.description, this.parseBySaving());
}
}
36 changes: 28 additions & 8 deletions src/main/java/duke/tasks/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,52 @@

import duke.Parser;

import java.time.LocalDate;
import java.time.LocalDateTime;

public class Events extends Task {
protected LocalDate startDate;
protected LocalDate endDate;

static protected String DEFAULT_TIME = "2359";

protected LocalDateTime startDate;
protected LocalDateTime endDate;

public Events(String description, String startDate, String endDate) {
super(description);
this.startDate = Parser.stringToDate(startDate);
this.endDate = Parser.stringToDate(endDate);
this.startDate = Parser.stringToDateTime(startDate);
this.endDate = Parser.stringToDateTime(endDate);
}

public String getStart() {
return Parser.dateTimeToString(startDate);
}

public String getEnd() {
return Parser.dateTimeToString(endDate);
}


@Override
public String getStatusIcon() {
return "[E]" + super.getStatusIcon();
}

@Override
public String getDescription() {
return super.getDescription() + " (from: " + this.startDate +
" to: " + this.endDate + ")";
return super.getDescription() + " (from: " + this.getStart() +
" to: " + this.getEnd() + ")";
}

public String parseStartSaving() {
return Parser.dateTimeSaving(startDate);
}

public String parseEndSaving() {
return Parser.dateTimeSaving(startDate);
}

@Override
public String saveString() {
return String.format("E|%s|%s|%s|%s", super.saveString(), super.description,
this.startDate, this.endDate);
this.parseStartSaving(), this.parseEndSaving());
}
}