Skip to content

Commit

Permalink
Merge pull request nus-cs2103-AY2021S1#73 from MerlinLim/meeting
Browse files Browse the repository at this point in the history
Implement DateTime for Fields To and From
  • Loading branch information
MerlinLim authored Oct 18, 2020
2 parents 562b095 + 35122c4 commit 4cb5e84
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 96 deletions.
53 changes: 7 additions & 46 deletions src/main/java/seedu/address/model/meeting/meeting/From.java
Original file line number Diff line number Diff line change
@@ -1,60 +1,26 @@
package seedu.address.model.meeting.meeting;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.text.SimpleDateFormat;
import java.util.Date;
import seedu.address.model.util.DateTime;

/**
* Represents a Meeting's from in the meeting book.
*/
public class From {
public static final String MESSAGE_CONSTRAINTS =
"From should be in the format of MM/DD/YYYY or MM/DD/YYYY HH:mm, and should not be blank."
+ "Note: Single digit month, day, and minute can start with a leading zero.";
/*
* Format should be MM/DD/YYYY or MM/DD/YY HH:mm
* Single digit month, day, and minute can start with a leading zero.
* Solution below adapted from https://stackoverflow.com/a/51231
*/

// TODO: change back
// public static final String VALIDATION_REGEX = "[0-9]{2}/[0-9]{2}/[0-9]{4} [0-23]{2}:[0-59]{2}";
public static final String VALIDATION_REGEX = "[^\\s].*";

public final Date value;
public final String valueString;
public class From extends DateTime {

/**
* Constructs a {@code from}.
* @param from A valid from.
* Constructs a {@code From}.
*
* @param from A valid From.
*/
// public From(String from) throws ParseException {
// requireNonNull(from);
// checkArgument(isValidFrom(from), MESSAGE_CONSTRAINTS);
// valueString = from;
// value = DateParser.parseDate(from);
// }

public From(String from) {
requireNonNull(from);
checkArgument(isValidFrom(from), MESSAGE_CONSTRAINTS);
valueString = from;
value = new Date();
super(from);
}

/**
* Returns true if a given string is a valid from.
*/
public static boolean isValidFrom(String test) {
return test.matches(VALIDATION_REGEX);
}

// ToDo: Discuss with team
@Override
public String toString() {
return new SimpleDateFormat("MMM d yyyy").format(value);
return isValidDateTime(test);
}

@Override
Expand All @@ -64,9 +30,4 @@ public boolean equals(Object other) {
&& value.equals(((From) other).value));
}

@Override
public int hashCode() {
return value.hashCode();
}

}
52 changes: 4 additions & 48 deletions src/main/java/seedu/address/model/meeting/meeting/To.java
Original file line number Diff line number Diff line change
@@ -1,65 +1,26 @@
package seedu.address.model.meeting.meeting;

import static java.util.Objects.requireNonNull;
import static seedu.address.commons.util.AppUtil.checkArgument;

import java.text.SimpleDateFormat;
import java.util.Date;
import seedu.address.model.util.DateTime;

/**
* Represents a Meeting's to in the meeting book.
*/
public class To {
public static final String MESSAGE_CONSTRAINTS =
"Tos should be in the format of MM/DD/YYYY or MM/DD/YYYY HH:mm, and should not be blank."
+ "Note: Single digit month, day, and minute can start with a leading zero.";

/*
* Format should be MM/DD/YYYY or MM/DD/YY HH:mm
* Single digit month, day, and minute can start with a leading zero.
* Solution below adapted from https://stackoverflow.com/a/51231
*/
// TODO: change back
// public static final String VALIDATION_REGEX = "[0-9]{2}/[0-9]{2}/[0-9]{4} [0-23]{2}:[0-59]{2}";
public static final String VALIDATION_REGEX = "[^\\s].*";

public final Date value;

public final String valueString;
public class To extends DateTime {

/**
* Constructs a {@code To}.
*
* @param to A valid To.
*/

// // Todo: Discuss with team
// public To(String to) throws ParseException {
// requireNonNull(to);
// checkArgument(isValidTo(to), MESSAGE_CONSTRAINTS);
// valueString = to;
// value = DateParser.parseDate(to);
// }

// Todo: Discuss with team
public To(String to) {
requireNonNull(to);
checkArgument(isValidTo(to), MESSAGE_CONSTRAINTS);
valueString = to;
value = new Date();
super(to);
}

/**
* Returns true if a given string is a valid To.
*/
public static boolean isValidTo(String test) {
return test.matches(VALIDATION_REGEX);
}

// TODO: abstract?
@Override
public String toString() {
return new SimpleDateFormat("MMM d yyyy").format(value);
return isValidDateTime(test);
}

@Override
Expand All @@ -69,9 +30,4 @@ public boolean equals(Object other) {
&& value.equals(((To) other).value));
}

@Override
public int hashCode() {
return value.hashCode();
}

}
4 changes: 2 additions & 2 deletions src/test/java/seedu/address/testutil/TypicalMeetings.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class TypicalMeetings {

public static final String TITLE_D = "Mid v1.2";
public static final String DESCRIPTION_D = "Discuss features";
public static final String FROM_D = "12-24-2020 08:00";
public static final String TO_D = "12-24-2020 08:00";
public static final String FROM_D = "12-12-2020 08:00";
public static final String TO_D = "12-12-2020 08:00";
public static final String CONTACTS_D = "6,7,8";
public static final String LOCATION_D = "Somewhere";

Expand Down

0 comments on commit 4cb5e84

Please sign in to comment.