forked from nus-cs2103-AY2324S1/tp
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/chonguschonguschongus/tp
- Loading branch information
Showing
26 changed files
with
699 additions
and
105 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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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
73 changes: 73 additions & 0 deletions
73
src/main/java/seedu/address/model/appointment/AppointmentTime.java
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package seedu.address.model.appointment; | ||
|
||
import static java.util.Objects.requireNonNull; | ||
import static seedu.address.commons.util.AppUtil.checkArgument; | ||
|
||
import java.time.LocalDateTime; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
|
||
/** | ||
* Represents the time of an appointment. | ||
* Guarantees: immutable; is valid as declared in {@link #isValidAppointmentTime(String)} | ||
*/ | ||
public class AppointmentTime implements Comparable<AppointmentTime> { | ||
|
||
public static final String MESSAGE_CONSTRAINTS = "AppointmentTime should be in the format of yyyy-mm-dd HH:mm:ss\n"; | ||
public static final DateTimeFormatter FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); | ||
public final LocalDateTime value; | ||
|
||
/** | ||
* Constructs a {@code AppointmentTime}. | ||
* | ||
* @param appointmentTime A valid ic. | ||
*/ | ||
public AppointmentTime(String appointmentTime) { | ||
requireNonNull(appointmentTime); | ||
checkArgument(isValidAppointmentTime(appointmentTime), MESSAGE_CONSTRAINTS); | ||
value = LocalDateTime.parse(appointmentTime, FORMATTER); | ||
} | ||
|
||
/** | ||
* Returns true if a given string is a valid appointmentTime. | ||
*/ | ||
public static boolean isValidAppointmentTime(String test) { | ||
try { | ||
LocalDateTime.parse(test, FORMATTER); | ||
} catch (DateTimeParseException e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return value.format(FORMATTER); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (other == this) { | ||
return true; | ||
} | ||
|
||
// instanceof handles nulls | ||
if (!(other instanceof AppointmentTime)) { | ||
return false; | ||
} | ||
|
||
AppointmentTime otherAppointmentTime = (AppointmentTime) other; | ||
return value.equals(otherAppointmentTime.value); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return value.hashCode(); | ||
} | ||
|
||
@Override | ||
public int compareTo(AppointmentTime o) { | ||
return this.value.compareTo(o.value); | ||
} | ||
} |
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
Oops, something went wrong.