-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
131 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,74 @@ | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Deadline extends Task { | ||
|
||
protected String by; | ||
|
||
protected LocalDate deadlineDate; | ||
|
||
protected LocalDateTime deadLineDateAndTime; | ||
|
||
public Deadline(String description, String by) { | ||
super(description); | ||
this.deadlineDate = parseDate(by); | ||
this.deadLineDateAndTime = parseDateTime(by); | ||
this.by = by; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[D]" + super.toString() + "(by: " + by + ")"; | ||
if (deadlineDate != null) { | ||
String outputDate = deadlineDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); | ||
return "[D]" + super.toString() + "(by: " + outputDate + ")"; | ||
} else if (deadLineDateAndTime != null) { | ||
String outputDateTime = deadLineDateAndTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); | ||
return "[D]" + super.toString() + "(by: " + outputDateTime + ")"; | ||
} else { | ||
return "[D]" + super.toString() + "(by: " + by + ")"; | ||
} | ||
} | ||
@Override | ||
public String writeToFile() { | ||
return "D | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + " | " + by; | ||
String printedStuff = "D | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + "| "; | ||
return printedStuff + this.by; | ||
} | ||
|
||
protected LocalDate parseDate(String date) { | ||
List<DateTimeFormatter> formats = new ArrayList<>(); | ||
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | ||
formats.add(DateTimeFormatter.ofPattern("dd/MM/yyyy")); | ||
formats.add(DateTimeFormatter.ofPattern("d/M/yyyy")); | ||
|
||
for (int i = 0; i < formats.size(); i++) { | ||
try { | ||
return LocalDate.parse(date, formats.get(i)); | ||
} catch (DateTimeParseException e) { | ||
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
protected LocalDateTime parseDateTime(String date) { | ||
List<DateTimeFormatter> formats = new ArrayList<>(); | ||
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); | ||
formats.add(DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm")); | ||
formats.add(DateTimeFormatter.ofPattern("d/MM/yyyy HHmm")); | ||
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm")); | ||
|
||
for (int i = 0; i < formats.size(); i++) { | ||
try { | ||
return LocalDateTime.parse(date, formats.get(i)); | ||
} catch (DateTimeParseException e) { | ||
|
||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,85 @@ | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Event extends Task { | ||
|
||
protected String from; | ||
protected String to; | ||
|
||
protected LocalDate fromDate; | ||
protected LocalDate toDate; | ||
|
||
protected LocalDateTime fromDateTime; | ||
protected LocalDateTime toDateTime; | ||
|
||
public Event(String description, String from, String to) { | ||
super(description); | ||
this.fromDate = parseDate(from); | ||
this.toDate = parseDate(to); | ||
this.fromDateTime = parseDateTime(from); | ||
this.toDateTime = parseDateTime(to); | ||
this.from = from; | ||
this.to = to; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "[E]" + super.toString() + "(from: " + from + " to: " + to + ")"; | ||
String fromWhen = from; | ||
String toWhen = to; | ||
|
||
if (fromDate != null) { | ||
fromWhen = fromDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); | ||
} else if (fromDateTime != null) { | ||
fromWhen = fromDateTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); | ||
} | ||
|
||
if (toDate != null) { | ||
toWhen = toDate.format(DateTimeFormatter.ofPattern("MMM dd yyyy")); | ||
} else if (toDateTime != null) { | ||
toWhen = toDateTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); | ||
} | ||
return "[E]" + super.toString() + "(from: " + fromWhen + " to: " + toWhen + ")"; | ||
} | ||
@Override | ||
public String writeToFile() { | ||
return "E | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + " | " + from + " to " + to; | ||
return "E | " + (getIsDone() ? "1" : "0") + " | " + getDescription() + "| " + from + " to " + to; | ||
} | ||
|
||
protected LocalDate parseDate(String date) { | ||
List<DateTimeFormatter> formats = new ArrayList<>(); | ||
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd")); | ||
formats.add(DateTimeFormatter.ofPattern("dd/MM/yyyy")); | ||
formats.add(DateTimeFormatter.ofPattern("d/M/yyyy")); | ||
|
||
for (int i = 0; i < formats.size(); i++) { | ||
try { | ||
return LocalDate.parse(date, formats.get(i)); | ||
} catch (DateTimeParseException e) { | ||
|
||
} | ||
} | ||
return null; | ||
} | ||
|
||
protected LocalDateTime parseDateTime(String date) { | ||
List<DateTimeFormatter> formats = new ArrayList<>(); | ||
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd HHmm")); | ||
formats.add(DateTimeFormatter.ofPattern("dd/MM/yyyy HHmm")); | ||
formats.add(DateTimeFormatter.ofPattern("d/MM/yyyy HHmm")); | ||
formats.add(DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm")); | ||
|
||
for (int i = 0; i < formats.size(); i++) { | ||
try { | ||
return LocalDateTime.parse(date, formats.get(i)); | ||
} catch (DateTimeParseException e) { | ||
|
||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,2 @@ | ||
T | 0 | this | ||
D | 1 | that | 2pm mondayee | ||
E | 0 | party | 2pm sunday to 3pm monday | ||
T | 1 | thing that | ||
E | 0 | do this | 20/12/2020 1900 to 21/12/2020 1001 | ||
D | 1 | finish this | 1/02/1990 0001 |