Skip to content

Commit

Permalink
B-DoWithinPeriodTasks
Browse files Browse the repository at this point in the history
  • Loading branch information
CEGLincoln committed Sep 18, 2019
2 parents ebe621c + 263656b commit e017dc3
Show file tree
Hide file tree
Showing 9 changed files with 146 additions and 10 deletions.
20 changes: 18 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ plugins {
id 'java'
id 'application'
id 'checkstyle'
id 'com.github.johnrengelman.shadow' version '5.1.0'
}

group 'seedu.duke'
Expand All @@ -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"
Expand All @@ -20,6 +32,10 @@ run {
standardInput = System.in
}

checkstyle {
toolVersion = '8.23'
dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.5.0'
}

test {
useJUnitPlatform()
}
4 changes: 4 additions & 0 deletions data/tasks.txt
Original file line number Diff line number Diff line change
@@ -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
60 changes: 60 additions & 0 deletions docs/AboutUs.md
Original file line number Diff line number Diff line change
@@ -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:
16 changes: 16 additions & 0 deletions src/main/java/duke/parser/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 :-(");
}
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/duke/task/Deadline.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions src/main/java/duke/task/DoWithinPeriodTasks.java
Original file line number Diff line number Diff line change
@@ -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";
}
}
11 changes: 9 additions & 2 deletions src/main/java/duke/task/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/duke/task/Task.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
7 changes: 6 additions & 1 deletion src/test/java/DukeTest.java
Original file line number Diff line number Diff line change
@@ -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.*;
Expand All @@ -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
Expand Down

0 comments on commit e017dc3

Please sign in to comment.