forked from nus-cs2103-AY2223S1/ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Event.java
51 lines (45 loc) · 1.56 KB
/
Event.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package duke;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
import java.time.format.DateTimeParseException;
/**
* Represents an event, which is a specific type of task.
*
* @author Liu Han
*/
public class Event extends Task {
protected LocalDate at;
/**
* Event Constructor
* @param description Description of the event.
* @param at Date of the event happening.
* @throws DukeException If date is in an invalid format.
*/
public Event(String description, String at) throws DukeException {
super(description);
try {
this.at = LocalDate.parse(at);
} catch (DateTimeParseException err) {
throw new DukeException("The date format should be: yyyy-MM-dd");
}
// this.at = LocalDate.parse(at, DateTimeFormatter.ofPattern("yyyy-MM-dd"));
}
/**
* Prints the event when list is called by the user
* @return String in the format <b>[E][isDone] description (at: MMM d yyyy)</b>.
*/
@Override
public String toString() {
return "[E]" + super.toString() + " (at: "
+ this.at.format(DateTimeFormatter.ofPattern("MMM d yyyy")) + ")";
}
/**
* Saves the event into a string and writes into a .txt file.
* @return String in the format <b>E | isDone | description | yyyy-MM-dd</b>.
*/
@Override
public String toSave() {
return "E | " + (this.isDone ? "1 | " : "0 | ") + this.getDescription() +
" | " + this.at.format(DateTimeFormatter.ofPattern("yyyy-MM-dd")) + "\n";
}
}