diff --git a/build.gradle b/build.gradle index 81a190b87d..04b7ff3e97 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ plugins { id 'java' id 'application' id 'checkstyle' + id 'com.github.johnrengelman.shadow' version '5.1.0' } group 'seedu.duke' @@ -11,6 +12,17 @@ repositories { mavenCentral() } +shadowJar { + archiveBaseName = "mid-v1.1" + archiveVersion = "1.1" + archiveClassifier = null + archiveAppendix = null +} + +checkstyle { + toolVersion = '8.23' +} + application { // Change this to your main class. mainClassName = "duke/Duke" @@ -20,6 +32,10 @@ run { standardInput = System.in } -checkstyle { - toolVersion = '8.23' +dependencies { + testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0' +} + +test { + useJUnitPlatform() } \ No newline at end of file diff --git a/data/tasks.txt b/data/tasks.txt new file mode 100644 index 0000000000..ed30e11312 --- /dev/null +++ b/data/tasks.txt @@ -0,0 +1,4 @@ +T|0|read book +D|0|return book |tmr +E|0|meeting |2019-09-09 +[P][✘] pain (from: TODO to: TODO diff --git a/docs/AboutUs.md b/docs/AboutUs.md new file mode 100644 index 0000000000..f0e1210895 --- /dev/null +++ b/docs/AboutUs.md @@ -0,0 +1,60 @@ +# About Us + +Duke - Level 3 was developed by the [se-edu](https://se-edu.github.io/docs/Team.html) team. +*{The dummy content given below serves as a placeholder to be used by future forks of the project.}* + +We are a team based in the [School of Computing, National University of Singapore](http://www.comp.nus.edu.sg/). + + + +## Project Team + +### Hafidz Bin Hussain + +[photo here] + +[[github](https://github.com/9hafidz6)] [profolio] + +Role: Team Lead + +Responsibilities: + +### Sara Djambazovska + +[photo here] + +[[github](https://github.com/saradj/)] [profolio] + +Role: Developer + +Responsibilities: + +### Jiahan Yu + +[photo here] + +[[github](https://github.com/saradj/)] [profolio] + +Role: Developer + +Responsibilities: + +### Goh Zhen Hao Joey + +[photo here] + +[[github](https://github.com/x3chillax)] [profolio] + +Role: Developer + +Responsibilities: + +### Lincoln Lim + +[photo here] + +[[github](https://github.com/CEGLincoln)] [profolio] + +Role: Developer + +Responsibilities: \ No newline at end of file diff --git a/src/main/java/duke/parser/Parser.java b/src/main/java/duke/parser/Parser.java index 3c5594fea4..6a676085e1 100644 --- a/src/main/java/duke/parser/Parser.java +++ b/src/main/java/duke/parser/Parser.java @@ -4,6 +4,7 @@ import duke.command.*; import duke.exception.DukeException; import duke.task.Deadline; +import duke.task.DoWithinPeriodTasks; import duke.task.Event; import duke.task.Todo; @@ -63,6 +64,21 @@ public static Command parse(String fullCommand) throws DukeException { int taskNb = Integer.parseInt(splitted[1]); return new DeleteCommand(taskNb - 1); } else throw new DukeException("Need a task number after done!"); + case "period": + if ((splitted.length == 1) || splitted[1].isEmpty()) + throw new DukeException("The description of a period cannot be empty."); + String[] getPart = splitted[1].split("/from ", 2); + if (getPart.length < 2) + throw new DukeException("The description of a period must contain /from date!"); + String[] part = getPart[1].split("/to ", 2); + if (part.length < 2) + throw new DukeException("NO"); + try { + return new AddCommand(new DoWithinPeriodTasks(getPart[0], part[0], part[1])); + } + catch(Exception e){ + throw new DukeException("NO"); + } default: throw new DukeException("I'm sorry, but I don't know what that means :-("); } diff --git a/src/main/java/duke/task/Deadline.java b/src/main/java/duke/task/Deadline.java index eabbfe1782..81343da26a 100644 --- a/src/main/java/duke/task/Deadline.java +++ b/src/main/java/duke/task/Deadline.java @@ -15,21 +15,23 @@ public class Deadline extends Task { public Deadline(String description, String by) { super(description); this.by = by; - this.date = getDate(by); + this.date = super.getDate(by); } @Override public String toString() { - return (getDate(by) == null) ? "[D]" + super.toString() + "(by: " + by + ")" : "[D]" + super.toString() + "(by: " + getDateString(date) + ")"; + return (super.getDate(by) == null) ? "[D]" + super.toString() + "(by: " + by + ")" : "[D]" + super.toString() + "(by: " + getDateString(date) + ")"; } /** * Returns the data by which the deadline must be met * @return date the final {@link Date } for finishing the Deadline */ + /* public Date getDate() { return date; } + */ /** * Returns the {@link Date } instance as a String to be printed in the file diff --git a/src/main/java/duke/task/DoWithinPeriodTasks.java b/src/main/java/duke/task/DoWithinPeriodTasks.java new file mode 100644 index 0000000000..a7099212ca --- /dev/null +++ b/src/main/java/duke/task/DoWithinPeriodTasks.java @@ -0,0 +1,25 @@ +package duke.task; + +import java.util.Date; + +public class DoWithinPeriodTasks extends Task{ + + private Date from; + private Date to; + + public DoWithinPeriodTasks(String d, String f, String t) { + //CONSTRUCTOR + super(d); + from = super.getDate(f); + to = super.getDate(t); + } + + public String printInFile(){ + return this.toString(); + } + + @Override + public String toString(){ + return "[P]" + super.toString() + "(from: " + "TODO" + " to: " + "TODO"; + } +} diff --git a/src/main/java/duke/task/Event.java b/src/main/java/duke/task/Event.java index 1bd1db118d..7ef127f685 100644 --- a/src/main/java/duke/task/Event.java +++ b/src/main/java/duke/task/Event.java @@ -15,7 +15,7 @@ public class Event extends Task { public Event(String description, String at) { super(description); this.at = at; - this.date = getDate(at); + this.date = super.getDate(at); } @Override @@ -39,7 +39,14 @@ private String getDateString(Date date) { if (date == null) return at; LocalDate localDate = date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate(); - String pattern = at.length() > 11 ? "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy, ha " : "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy"; + //String pattern = at.length() > 11 ? "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy, ha " : "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy"; + String pattern; + if(at.length() > 11){ + pattern = "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy, ha "; + } + else{ + pattern = "d'" + getDaySuffix(localDate.getDayOfMonth()) + "' 'of' MMMM yyyy"; + } SimpleDateFormat formatter = new SimpleDateFormat(pattern); return formatter.format(date); } diff --git a/src/main/java/duke/task/Task.java b/src/main/java/duke/task/Task.java index 1c8c5e3916..7f7cef508f 100644 --- a/src/main/java/duke/task/Task.java +++ b/src/main/java/duke/task/Task.java @@ -83,14 +83,15 @@ static String getDaySuffix(int n) { * @param date String in the format "dd/MM/yyyy hhmm" or "dd/MM/yyyy", used to extract a {@link Date} instance from * @return the {@link Date} instance created from the argument string */ - static Date getDate(String date) { + protected Date getDate(String date) { DateFormat dateFormat = (date.length() > 11) ? new SimpleDateFormat("dd/MM/yyyy hhmm") : new SimpleDateFormat("dd/MM/yyyy"); try { - dateFormat.parse(date); + //dateFormat.parse(date); return dateFormat.parse(date); } catch (ParseException e) { //case the date was not valid! + return new Date(); } - return null; + //return null; } } \ No newline at end of file diff --git a/src/test/java/DukeTest.java b/src/test/java/DukeTest.java index 99e0e46a44..83d4bada25 100644 --- a/src/test/java/DukeTest.java +++ b/src/test/java/DukeTest.java @@ -1,4 +1,9 @@ +import duke.Duke; +import duke.command.AddCommand; +import duke.command.Command; +import duke.command.ExitCommand; import duke.exception.DukeException; +import duke.parser.Parser; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -12,7 +17,7 @@ public void dummyTest(){ @Test public void testExitCommand() throws DukeException { Duke duke= new Duke("data/tasks.txt"); - Command c=Parser.parse("bye"); + Command c= Parser.parse("bye"); assertTrue(c instanceof ExitCommand); } @Test