-
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.
Level-8 deadline done, event left to do
- Loading branch information
1 parent
8708c8a
commit a6a9d84
Showing
4 changed files
with
77 additions
and
6 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,79 @@ | ||
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 outputDate = deadLineDateAndTime.format(DateTimeFormatter.ofPattern("MMM dd yyyy HH:mm")); | ||
return "[D]" + super.toString() + "(by: " + outputDate + ")"; | ||
} 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() + " | "; | ||
if (deadlineDate != null) { | ||
return printedStuff + this.deadlineDate; | ||
} else if (deadLineDateAndTime != null) { | ||
return printedStuff + this.deadLineDateAndTime; | ||
} else { | ||
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")); | ||
|
||
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
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 @@ | ||
T | 0 | this | ||
D | 1 | that | 2pm mondayee | ||
E | 0 | party | 2pm sunday to 3pm monday | ||
T | 1 | thing that | ||
D | 0 | do this | 2020-02-12T18:00 |