From fa2b17aabb0d683d0179d8b484da47973d631c37 Mon Sep 17 00:00:00 2001 From: Hwww23 <122247552+Hwww23@users.noreply.github.com> Date: Tue, 19 Mar 2024 21:54:21 +0800 Subject: [PATCH 01/10] Add dates to Student details --- docs/UserGuide.md | 5 +- .../java/seedu/address/logic/Messages.java | 4 +- .../address/logic/commands/AddCommand.java | 3 + .../address/logic/commands/EditCommand.java | 16 ++++- .../logic/parser/AddCommandParser.java | 7 +- .../seedu/address/logic/parser/CliSyntax.java | 1 + .../address/logic/parser/ParserUtil.java | 19 ++++++ .../seedu/address/model/person/DateTime.java | 68 +++++++++++++++++++ .../seedu/address/model/person/Person.java | 11 ++- .../address/model/util/SampleDataUtil.java | 19 ++++-- .../address/storage/JsonAdaptedDateTime.java | 32 +++++++++ .../address/storage/JsonAdaptedPerson.java | 18 ++++- .../java/seedu/address/ui/PersonCard.java | 11 +++ src/main/resources/view/PersonListCard.fxml | 1 + .../duplicatePersonAddressBook.json | 2 + .../typicalPersonsAddressBook.json | 7 ++ .../logic/commands/CommandTestUtil.java | 6 ++ .../logic/parser/AddCommandParserTest.java | 32 ++++++--- .../address/logic/parser/ParserUtilTest.java | 51 ++++++++++++++ .../address/model/person/DateTimeTest.java | 24 +++++++ .../address/model/person/PersonTest.java | 3 +- .../storage/JsonAdaptedPersonTest.java | 41 +++++++---- .../seedu/address/testutil/PersonBuilder.java | 14 +++- .../address/testutil/TypicalPersons.java | 10 +-- 24 files changed, 360 insertions(+), 45 deletions(-) create mode 100644 src/main/java/seedu/address/model/person/DateTime.java create mode 100644 src/main/java/seedu/address/storage/JsonAdaptedDateTime.java create mode 100644 src/test/java/seedu/address/model/person/DateTimeTest.java diff --git a/docs/UserGuide.md b/docs/UserGuide.md index 8a77a9f114c..e7427dd1c86 100644 --- a/docs/UserGuide.md +++ b/docs/UserGuide.md @@ -76,15 +76,16 @@ Format: `help` Adds a student to the address book. -Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [g/GRADE] [s/SUBJECT] [t/TAG]…​` +Format: `add n/NAME p/PHONE_NUMBER e/EMAIL a/ADDRESS [g/GRADE] [s/SUBJECT] [d/DATETIME] [t/TAG]…​`
:bulb: **Tip:** A person can have any number of tags (including 0)
* Grade should only contain a single letter from A to D, with plus(+), minus(-) or neither. +* DateTime should be in yyyy-mm-dd hhmm Examples: -* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/B+ s/Mathematics` +* `add n/John Doe p/98765432 e/johnd@example.com a/John street, block 123, #01-01 g/B+ s/Mathematics d/2024-02-03 1800` * `add n/Betsy Crowe t/friend e/betsycrowe@example.com a/Newgate Prison p/1234567 t/criminal` ### Listing all persons : `list` diff --git a/src/main/java/seedu/address/logic/Messages.java b/src/main/java/seedu/address/logic/Messages.java index e72813c4c67..2ee222b143d 100644 --- a/src/main/java/seedu/address/logic/Messages.java +++ b/src/main/java/seedu/address/logic/Messages.java @@ -47,7 +47,9 @@ public static String format(Person person) { .append(person.getGrade()) .append("; Subject: ") .append(person.getSubject()) - .append("; Tags: "); + .append("; DateTime: "); + person.getDateTimes().forEach(builder::append); + builder.append("; Tags: "); person.getTags().forEach(builder::append); return builder.toString(); } diff --git a/src/main/java/seedu/address/logic/commands/AddCommand.java b/src/main/java/seedu/address/logic/commands/AddCommand.java index db1da7bfdc8..6128ed35ab5 100644 --- a/src/main/java/seedu/address/logic/commands/AddCommand.java +++ b/src/main/java/seedu/address/logic/commands/AddCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; @@ -30,6 +31,7 @@ public class AddCommand extends Command { + PREFIX_ADDRESS + "ADDRESS " + "[" + PREFIX_GRADE + "GRADE] " + "[" + PREFIX_SUBJECT + "SUBJECT] " + + "[" + PREFIX_DATETIME + "DATETIME] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " " + PREFIX_NAME + "John Doe " @@ -38,6 +40,7 @@ public class AddCommand extends Command { + PREFIX_ADDRESS + "311, Clementi Ave 2, #02-25 " + PREFIX_GRADE + "4.0 " + PREFIX_SUBJECT + "Mathematics " + + PREFIX_DATETIME + "2024-03-02 1800" + PREFIX_TAG + "friends " + PREFIX_TAG + "owesMoney"; diff --git a/src/main/java/seedu/address/logic/commands/EditCommand.java b/src/main/java/seedu/address/logic/commands/EditCommand.java index 94ff22d919b..63119d4dca2 100644 --- a/src/main/java/seedu/address/logic/commands/EditCommand.java +++ b/src/main/java/seedu/address/logic/commands/EditCommand.java @@ -2,6 +2,7 @@ import static java.util.Objects.requireNonNull; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; @@ -24,6 +25,7 @@ import seedu.address.logic.commands.exceptions.CommandException; import seedu.address.model.Model; import seedu.address.model.person.Address; +import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; @@ -49,6 +51,7 @@ public class EditCommand extends Command { + "[" + PREFIX_ADDRESS + "ADDRESS] " + "[" + PREFIX_GRADE + "GRADE] " + "[" + PREFIX_SUBJECT + "SUBJECT] " + + "[" + PREFIX_DATETIME + "DATETIME] " + "[" + PREFIX_TAG + "TAG]...\n" + "Example: " + COMMAND_WORD + " 1 " + PREFIX_PHONE + "91234567 " @@ -107,10 +110,11 @@ private static Person createEditedPerson(Person personToEdit, EditPersonDescript Address updatedAddress = editPersonDescriptor.getAddress().orElse(personToEdit.getAddress()); Grade updatedGrade = personToEdit.getGrade(); Subject updatedSubject = personToEdit.getSubject(); + Set updatedDateTime = editPersonDescriptor.getDateTime().orElse(personToEdit.getDateTimes()); Set updatedTags = editPersonDescriptor.getTags().orElse(personToEdit.getTags()); return new Person(updatedName, updatedPhone, updatedEmail, updatedAddress, - updatedGrade, updatedSubject, updatedTags); + updatedGrade, updatedSubject, updatedDateTime, updatedTags); } @Override @@ -146,6 +150,7 @@ public static class EditPersonDescriptor { private Phone phone; private Email email; private Address address; + private Set dateTime; private Set tags; public EditPersonDescriptor() {} @@ -159,6 +164,7 @@ public EditPersonDescriptor(EditPersonDescriptor toCopy) { setPhone(toCopy.phone); setEmail(toCopy.email); setAddress(toCopy.address); + setDateTime(toCopy.dateTime); setTags(toCopy.tags); } @@ -201,6 +207,14 @@ public Optional
getAddress() { return Optional.ofNullable(address); } + public void setDateTime(Set dateTime) { + this.dateTime = (dateTime != null) ? new HashSet<>(dateTime) : null; + } + + public Optional> getDateTime() { + return (dateTime != null) ? Optional.of(Collections.unmodifiableSet(dateTime)) : Optional.empty(); + } + /** * Sets {@code tags} to this object's {@code tags}. * A defensive copy of {@code tags} is used internally. diff --git a/src/main/java/seedu/address/logic/parser/AddCommandParser.java b/src/main/java/seedu/address/logic/parser/AddCommandParser.java index 51a45a8cf98..7532a841661 100644 --- a/src/main/java/seedu/address/logic/parser/AddCommandParser.java +++ b/src/main/java/seedu/address/logic/parser/AddCommandParser.java @@ -2,6 +2,7 @@ import static seedu.address.logic.Messages.MESSAGE_INVALID_COMMAND_FORMAT; import static seedu.address.logic.parser.CliSyntax.PREFIX_ADDRESS; +import static seedu.address.logic.parser.CliSyntax.PREFIX_DATETIME; import static seedu.address.logic.parser.CliSyntax.PREFIX_EMAIL; import static seedu.address.logic.parser.CliSyntax.PREFIX_GRADE; import static seedu.address.logic.parser.CliSyntax.PREFIX_NAME; @@ -15,6 +16,7 @@ import seedu.address.logic.commands.AddCommand; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; +import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; @@ -36,7 +38,7 @@ public class AddCommandParser implements Parser { public AddCommand parse(String args) throws ParseException { ArgumentMultimap argMultimap = ArgumentTokenizer.tokenize(args, PREFIX_NAME, PREFIX_PHONE, PREFIX_EMAIL, PREFIX_ADDRESS, PREFIX_TAG, - PREFIX_GRADE, PREFIX_SUBJECT); + PREFIX_GRADE, PREFIX_SUBJECT, PREFIX_DATETIME); if (!arePrefixesPresent(argMultimap, PREFIX_NAME, PREFIX_ADDRESS, PREFIX_PHONE, PREFIX_EMAIL) || !argMultimap.getPreamble().isEmpty()) { @@ -57,9 +59,10 @@ public AddCommand parse(String args) throws ParseException { if (argMultimap.getValue(PREFIX_SUBJECT).isPresent()) { subject = ParserUtil.parseSubject(argMultimap.getValue(PREFIX_SUBJECT).get()); } + Set dateTimeList = ParserUtil.parseDateTimes(argMultimap.getAllValues(PREFIX_DATETIME)); Set tagList = ParserUtil.parseTags(argMultimap.getAllValues(PREFIX_TAG)); - Person student = new Person(name, phone, email, address, grade, subject, tagList); + Person student = new Person(name, phone, email, address, grade, subject, dateTimeList, tagList); return new AddCommand(student); } diff --git a/src/main/java/seedu/address/logic/parser/CliSyntax.java b/src/main/java/seedu/address/logic/parser/CliSyntax.java index 320743a43c4..99ed37079fc 100644 --- a/src/main/java/seedu/address/logic/parser/CliSyntax.java +++ b/src/main/java/seedu/address/logic/parser/CliSyntax.java @@ -13,4 +13,5 @@ public class CliSyntax { public static final Prefix PREFIX_TAG = new Prefix("t/"); public static final Prefix PREFIX_GRADE = new Prefix("g/"); public static final Prefix PREFIX_SUBJECT = new Prefix("s/"); + public static final Prefix PREFIX_DATETIME = new Prefix("d/"); } diff --git a/src/main/java/seedu/address/logic/parser/ParserUtil.java b/src/main/java/seedu/address/logic/parser/ParserUtil.java index fb377de4813..f3a2e1d5cc5 100644 --- a/src/main/java/seedu/address/logic/parser/ParserUtil.java +++ b/src/main/java/seedu/address/logic/parser/ParserUtil.java @@ -10,6 +10,7 @@ import seedu.address.commons.util.StringUtil; import seedu.address.logic.parser.exceptions.ParseException; import seedu.address.model.person.Address; +import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; @@ -153,4 +154,22 @@ public static Subject parseSubject(String subject) throws ParseException { } return new Subject(trimmedSubject); } + + public static DateTime parseDateTime(String dateTime) throws ParseException { + requireNonNull(dateTime); + String trimmedDateTime = dateTime.trim(); + if (!DateTime.isValidDateTime(trimmedDateTime)) { + throw new ParseException(DateTime.MESSAGE_CONSTRAINTS); + } + return new DateTime(trimmedDateTime); + } + + public static Set parseDateTimes(Collection dateTimes) throws ParseException { + requireNonNull(dateTimes); + final Set dateTimeSet = new HashSet<>(); + for (String dateTime : dateTimes) { + dateTimeSet.add(parseDateTime(dateTime)); + } + return dateTimeSet; + } } diff --git a/src/main/java/seedu/address/model/person/DateTime.java b/src/main/java/seedu/address/model/person/DateTime.java new file mode 100644 index 00000000000..298ba960614 --- /dev/null +++ b/src/main/java/seedu/address/model/person/DateTime.java @@ -0,0 +1,68 @@ +package seedu.address.model.person; + +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeParseException; +import java.time.format.ResolverStyle; + +import static java.util.Objects.requireNonNull; +import static seedu.address.commons.util.AppUtil.checkArgument; + +public class DateTime { + public static final String MESSAGE_CONSTRAINTS = "DateTime should be in the format yyyy-mm-dd hhmm and after current day and time"; + public static final String VALIDATION_REGEX = "\\d{4}-\\d{2}-\\d{2} \\d{4}"; + public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm") + .withResolverStyle(ResolverStyle.STRICT); + + public final String value; + + /** + * Constructs a {@code DateTime}. + * + * @param dateTime A valid dateTime. + */ + public DateTime(String dateTime) { + requireNonNull(dateTime); + checkArgument(isValidDateTime(dateTime), MESSAGE_CONSTRAINTS); + value = dateTime; + } + + public static boolean isValidDateTime(String test) { + return test.matches(VALIDATION_REGEX) && isValidDateTimeFormat(test) && isAfterToday(test); + } + + private static boolean isValidDateTimeFormat(String test) { + try { + formatter.parse(test); + return true; + } catch (DateTimeParseException e) { + return false; + } + } + + private static boolean isAfterToday(String test) { + LocalDateTime now = LocalDateTime.now(); + LocalDateTime dateTime = LocalDateTime.parse(test, DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")); + return !dateTime.isBefore(now); + } + + @Override + public String toString() { + return '[' + value + ']'; + } + + @Override + public boolean equals(Object other) { + if (other == this) { + return true; + } + + // instanceof handles nulls + if (!(other instanceof DateTime)) { + return false; + } + + DateTime dateTime = (DateTime) other; + return value.equals(dateTime.value); + } +} diff --git a/src/main/java/seedu/address/model/person/Person.java b/src/main/java/seedu/address/model/person/Person.java index 00bbb58b5fc..ad745afe467 100644 --- a/src/main/java/seedu/address/model/person/Person.java +++ b/src/main/java/seedu/address/model/person/Person.java @@ -25,19 +25,21 @@ public class Person { private final Address address; private final Grade grade; private final Subject subject; + private final Set dateTimes = new HashSet<>(); private final Set tags = new HashSet<>(); /** * Every field must be present and not null. */ - public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject, Set tags) { - requireAllNonNull(name, phone, email, address, grade, subject, tags); + public Person(Name name, Phone phone, Email email, Address address, Grade grade, Subject subject, Set dateTimes, Set tags) { + requireAllNonNull(name, phone, email, address, grade, subject, dateTimes, tags); this.name = name; this.phone = phone; this.email = email; this.address = address; this.grade = grade; this.subject = subject; + this.dateTimes.addAll(dateTimes); this.tags.addAll(tags); } @@ -64,6 +66,9 @@ public Grade getGrade() { public Subject getSubject() { return subject; } + public Set getDateTimes() { + return Collections.unmodifiableSet(dateTimes); + } /** * Returns an immutable tag set, which throws {@code UnsupportedOperationException} @@ -106,6 +111,7 @@ public boolean equals(Object other) { && phone.equals(otherPerson.phone) && email.equals(otherPerson.email) && address.equals(otherPerson.address) + && dateTimes.equals(otherPerson.dateTimes) && tags.equals(otherPerson.tags); } @@ -124,6 +130,7 @@ public String toString() { .add("address", address) .add("grade", grade) .add("subject", subject) + .add("dateTimes", dateTimes) .add("tags", tags) .toString(); } diff --git a/src/main/java/seedu/address/model/util/SampleDataUtil.java b/src/main/java/seedu/address/model/util/SampleDataUtil.java index b0367e7f177..5ed405aef2f 100644 --- a/src/main/java/seedu/address/model/util/SampleDataUtil.java +++ b/src/main/java/seedu/address/model/util/SampleDataUtil.java @@ -7,6 +7,7 @@ import seedu.address.model.AddressBook; import seedu.address.model.ReadOnlyAddressBook; import seedu.address.model.person.Address; +import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; @@ -27,22 +28,22 @@ public static Person[] getSamplePersons() { return new Person[] { new Person(new Name("Alex Yeoh"), new Phone("87438807"), new Email("alexyeoh@example.com"), new Address("Blk 30 Geylang Street 29, #06-40"), EMPTY_GRADE, EMPTY_SUBJECT, - getTagSet("friends")), + getDateTimeSet("2024-03-02 1800"), getTagSet("friends")), new Person(new Name("Bernice Yu"), new Phone("99272758"), new Email("berniceyu@example.com"), new Address("Blk 30 Lorong 3 Serangoon Gardens, #07-18"), EMPTY_GRADE, EMPTY_SUBJECT, - getTagSet("colleagues", "friends")), + getDateTimeSet("2024-03-02 1800", "2024-03-04 2000"), getTagSet("colleagues", "friends")), new Person(new Name("Charlotte Oliveiro"), new Phone("93210283"), new Email("charlotte@example.com"), new Address("Blk 11 Ang Mo Kio Street 74, #11-04"), EMPTY_GRADE, EMPTY_SUBJECT, - getTagSet("neighbours")), + getDateTimeSet("2024-03-02 1800", "2024-03-21 1600"), getTagSet("neighbours")), new Person(new Name("David Li"), new Phone("91031282"), new Email("lidavid@example.com"), new Address("Blk 436 Serangoon Gardens Street 26, #16-43"), EMPTY_GRADE, EMPTY_SUBJECT, - getTagSet("family")), + getDateTimeSet("2024-03-14 2100"), getTagSet("family")), new Person(new Name("Irfan Ibrahim"), new Phone("92492021"), new Email("irfan@example.com"), new Address("Blk 47 Tampines Street 20, #17-35"), EMPTY_GRADE, EMPTY_SUBJECT, - getTagSet("classmates")), + getDateTimeSet("2024-03-18 2200"), getTagSet("classmates")), new Person(new Name("Roy Balakrishnan"), new Phone("92624417"), new Email("royb@example.com"), new Address("Blk 45 Aljunied Street 85, #11-31"), EMPTY_GRADE, EMPTY_SUBJECT, - getTagSet("colleagues")) + getDateTimeSet("2024-03-28 2300"), getTagSet("colleagues")) }; } @@ -63,4 +64,10 @@ public static Set getTagSet(String... strings) { .collect(Collectors.toSet()); } + public static Set getDateTimeSet(String... strings) { + return Arrays.stream(strings) + .map(DateTime::new) + .collect(Collectors.toSet()); + } + } diff --git a/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java new file mode 100644 index 00000000000..82487d77a97 --- /dev/null +++ b/src/main/java/seedu/address/storage/JsonAdaptedDateTime.java @@ -0,0 +1,32 @@ +package seedu.address.storage; + +import seedu.address.commons.exceptions.IllegalValueException; +import seedu.address.model.person.DateTime; + +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonValue; + +public class JsonAdaptedDateTime { + private final String dateTime; + + @JsonCreator + public JsonAdaptedDateTime(String dateTime) { + this.dateTime = dateTime; + } + + public JsonAdaptedDateTime(DateTime source) { + dateTime = source.value; + } + + @JsonValue + public String getDateTime() { + return dateTime; + } + + public DateTime toModelType() throws IllegalValueException { + if (!DateTime.isValidDateTime(dateTime)) { + throw new IllegalValueException(DateTime.MESSAGE_CONSTRAINTS); + } + return new DateTime(dateTime); + } +} diff --git a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java index 4f0c8ba43b4..4ed709e21d9 100644 --- a/src/main/java/seedu/address/storage/JsonAdaptedPerson.java +++ b/src/main/java/seedu/address/storage/JsonAdaptedPerson.java @@ -11,6 +11,7 @@ import seedu.address.commons.exceptions.IllegalValueException; import seedu.address.model.person.Address; +import seedu.address.model.person.DateTime; import seedu.address.model.person.Email; import seedu.address.model.person.Grade; import seedu.address.model.person.Name; @@ -32,6 +33,7 @@ class JsonAdaptedPerson { private final String address; private final String grade; private final String subject; + private final List dateTimes = new ArrayList<>(); private final List tags = new ArrayList<>(); /** @@ -41,13 +43,16 @@ class JsonAdaptedPerson { public JsonAdaptedPerson(@JsonProperty("name") String name, @JsonProperty("phone") String phone, @JsonProperty("email") String email, @JsonProperty("address") String address, @JsonProperty("grade") String grade, @JsonProperty("subject") String subject, - @JsonProperty("tags") List tags) { + @JsonProperty("dateTimes") List dateTimes, @JsonProperty("tags") List tags) { this.name = name; this.phone = phone; this.email = email; this.address = address; this.grade = grade; this.subject = subject; + if (tags != null) { + this.dateTimes.addAll(dateTimes); + } if (tags != null) { this.tags.addAll(tags); } @@ -63,6 +68,9 @@ public JsonAdaptedPerson(Person source) { address = source.getAddress().value; grade = source.getGrade().value; subject = source.getSubject().value; + dateTimes.addAll(source.getDateTimes().stream() + .map(JsonAdaptedDateTime::new) + .collect(Collectors.toList())); tags.addAll(source.getTags().stream() .map(JsonAdaptedTag::new) .collect(Collectors.toList())); @@ -79,6 +87,11 @@ public Person toModelType() throws IllegalValueException { personTags.add(tag.toModelType()); } + final List personDateTimes = new ArrayList<>(); + for (JsonAdaptedDateTime dateTime : dateTimes) { + personDateTimes.add(dateTime.toModelType()); + } + if (name == null) { throw new IllegalValueException(String.format(MISSING_FIELD_MESSAGE_FORMAT, Name.class.getSimpleName())); } @@ -127,8 +140,9 @@ public Person toModelType() throws IllegalValueException { } final Subject modelSubject = new Subject(subject); + final Set modelDateTimes = new HashSet<>(personDateTimes); final Set modelTags = new HashSet<>(personTags); - return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject, modelTags); + return new Person(modelName, modelPhone, modelEmail, modelAddress, modelGrade, modelSubject, modelDateTimes, modelTags); } } diff --git a/src/main/java/seedu/address/ui/PersonCard.java b/src/main/java/seedu/address/ui/PersonCard.java index ca87e4f1d87..95201467405 100644 --- a/src/main/java/seedu/address/ui/PersonCard.java +++ b/src/main/java/seedu/address/ui/PersonCard.java @@ -1,5 +1,7 @@ package seedu.address.ui; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; import java.util.Comparator; import javafx.fxml.FXML; @@ -43,6 +45,8 @@ public class PersonCard extends UiPart { @FXML private Label subject; @FXML + private FlowPane dateTimes; + @FXML private FlowPane tags; /** @@ -58,6 +62,13 @@ public PersonCard(Person person, int displayedIndex) { email.setText(person.getEmail().value); grade.setText(person.getGrade().value); subject.setText(person.getSubject().value); + dateTimes.setHgap(5); + person.getDateTimes().stream() + .sorted(Comparator.comparing(dateTime -> dateTime.value)) + .forEach(dateTime -> dateTimes.getChildren() + .add(new Label(LocalDateTime.parse(dateTime.value, + DateTimeFormatter.ofPattern("uuuu-MM-dd HHmm")) + .format(DateTimeFormatter.ofPattern("MMM d uuuu h:mma"))))); person.getTags().stream() .sorted(Comparator.comparing(tag -> tag.tagName)) .forEach(tag -> tags.getChildren().add(new Label(tag.tagName))); diff --git a/src/main/resources/view/PersonListCard.fxml b/src/main/resources/view/PersonListCard.fxml index 9e18c41bc30..51d79475371 100644 --- a/src/main/resources/view/PersonListCard.fxml +++ b/src/main/resources/view/PersonListCard.fxml @@ -33,6 +33,7 @@