Skip to content

Commit

Permalink
Merge pull request #73 from CS2103AUG2016-T14-C4/show-actual-time-on-UI
Browse files Browse the repository at this point in the history
Allow user to see the actual open and close time of tasks
  • Loading branch information
Skaty committed Nov 3, 2016
2 parents 342a686 + e0bff21 commit d1f39b2
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 17 deletions.
18 changes: 17 additions & 1 deletion src/main/java/seedu/task/model/task/DateTime.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ public class DateTime implements Comparable<DateTime> {

public static final String MESSAGE_DATETIME_CONSTRAINTS = "You have entered an invalid Date/Time format. For a complete list of all acceptable formats, please view our user guide.";

//@@author A0141052Y
private static final String DATE_TIME_DISPLAY_FORMAT = "%s (%s)";
//@@author

public final Optional<Instant> value;
private static PrettyTime p = new PrettyTime();

Expand Down Expand Up @@ -110,7 +114,7 @@ public String toString() {

if(value.isPresent()) {
DateTimeFormatter formatter =
DateTimeFormatter.ofLocalizedDateTime( FormatStyle.FULL )
DateTimeFormatter.ofLocalizedDateTime( FormatStyle.SHORT )
.withLocale( Locale.UK )
.withZone( ZoneId.systemDefault() );
return formatter.format( value.get() );
Expand All @@ -128,6 +132,17 @@ public String toPrettyString() {
}

//@@author A0141052Y
/**
* Gets a display friendly representation of the DateTime
*/
public String toDisplayString() {
if (this.toString().isEmpty()) {
return "";
} else {
return String.format(DATE_TIME_DISPLAY_FORMAT, this.toString(), this.toPrettyString());
}
}

public Long getSaveableValue() {
if(value.isPresent()) {
return this.value.get().toEpochMilli();
Expand Down Expand Up @@ -156,6 +171,7 @@ public int compareTo(DateTime o) {
}
}
//@@author

@Override
public boolean equals(Object other) {
return other == this // short circuit if same object
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/task/model/task/ReadOnlyTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public interface ReadOnlyTask {
*/
UniqueTagList getTags();

//@@author A0141052Y
/**
* Equality based on what is shown to the user. Useful for tests.
*/
Expand All @@ -30,10 +31,11 @@ default boolean isSameVisualStateAs(ReadOnlyTask other) {

// state checks here onwards
&& other.getName().equals(this.getName())
&& other.getOpenTime().toPrettyString().equals(this.getOpenTime().toPrettyString())
&& other.getCloseTime().toPrettyString().equals(this.getCloseTime().toPrettyString())
&& other.getOpenTime().toDisplayString().equals(this.getOpenTime().toDisplayString())
&& other.getCloseTime().toDisplayString().equals(this.getCloseTime().toDisplayString())
&& other.getImportance() == this.getImportance());
}
//@@author A0144939R

/**
* Returns true if both have the same state. (interfaces cannot override .equals)
Expand Down
6 changes: 4 additions & 2 deletions src/main/java/seedu/task/ui/TaskCard.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public class TaskCard extends UiPart{
@FXML
private Label closeTime;
//@@author

@FXML
private VBox cardDetails;

Expand Down Expand Up @@ -62,13 +63,14 @@ public void initialize() {
setVisualFlags();
showExtendedInformation();
}

//@@author A0144939R
private void setCardDetails() {
name.setText(task.getName().taskName);
id.setText(displayedIndex + ". ");

openTime.setText(task.getOpenTime().toPrettyString());
closeTime.setText(task.getCloseTime().toPrettyString());
openTime.setText(task.getOpenTime().toDisplayString());
closeTime.setText(task.getCloseTime().toDisplayString());

tagListPanel = TagListPanel.load(getPrimaryStage(), tagsListPlaceholder, task.getTags().getInternalList());
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/view/TaskListCard.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@
<HBox spacing="5" alignment="CENTER_LEFT">
<children>
<Label styleClass="cell_big_label" text="Start: "></Label>
<Label fx:id="openTime" styleClass="cell_big_label" text="\$openTime" />
<Label fx:id="openTime" styleClass="cell_big_label" text="\$openTime" />
</children>
</HBox>
<HBox spacing="5" alignment="CENTER_LEFT">
<children>
<Label styleClass="cell_big_label" text="End: "></Label>
<Label fx:id="closeTime" styleClass="cell_big_label" text="\$closeTime" />
<Label fx:id="closeTime" styleClass="cell_big_label" text="\$closeTime" />
</children>
</HBox>
</children>
Expand Down
17 changes: 11 additions & 6 deletions src/test/java/guitests/ChangePathCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,17 @@ public void changePath() throws InterruptedException {
//Try with unwritable file path
String unWriteableFilePath = TestUtil.getFilePathInSandboxFolder("unwritable.xml");
File unWriteableFolder = new File(unWriteableFilePath).getParentFile();
unWriteableFolder.setWritable(false);
Thread.sleep(300);
commandBox.runCommand("change-to " + unWriteableFilePath);
assertResultMessage(String.format(ChangePathCommand.MESSAGE_PATH_CHANGE_FAIL, unWriteableFilePath));
unWriteableFolder.setWritable(true);
Thread.sleep(300);

// check if test is run on Windows, as Windows has bad support for writeable flags
if (unWriteableFolder.setWritable(false)) {
Thread.sleep(300);
commandBox.runCommand("change-to " + unWriteableFilePath);
assertResultMessage(String.format(ChangePathCommand.MESSAGE_PATH_CHANGE_FAIL, unWriteableFilePath));
unWriteableFolder.setWritable(true);
Thread.sleep(300);
} else {
unWriteableFolder.setWritable(true);
}

//Try with empty String
String emptyPath = TestUtil.getFilePathInSandboxFolder("");
Expand Down
6 changes: 3 additions & 3 deletions src/test/java/guitests/guihandles/TaskCardHandle.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class TaskCardHandle extends GuiHandle {
private static final String OPEN_TIME_FIELD_ID = "#openTime";
private static final String CLOSE_TIME_FIELD_ID = "#closeTime";
private static final String DETAILS_FIELD_ID = "#cardDetails";

private Node node;

public TaskCardHandle(GuiRobot guiRobot, Stage primaryStage, Node node){
Expand Down Expand Up @@ -48,8 +48,8 @@ public boolean isDetailsShown() {

public boolean isSameTask(ReadOnlyTask task){
return getTaskName().equals(task.getName().taskName)
&& getOpenTime().equals(task.getOpenTime().toPrettyString())
&& getCloseTime().equals(task.getCloseTime().toPrettyString());
&& getOpenTime().equals(task.getOpenTime().toDisplayString())
&& getCloseTime().equals(task.getCloseTime().toDisplayString());
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/seedu/task/testutil/TypicalTestTasks.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public TypicalTestTasks() {
laundry = new TaskBuilder().withName("Meier").withOpenTime("tomorrow")
.withCloseTime("day after tomorrow").withImportance(false).withTags("urgent", "important").build();
carl = new TaskBuilder().withName("Meet Carl").withOpenTime("5 days from now")
.withCloseTime("13 days from now").build();
.withCloseTime("14 days from now").build();
daniel = new TaskBuilder().withName("Have lunch with Meier").withOpenTime("6 hours from now")
.withCloseTime("8 hours from now").build();
elle = new TaskBuilder().withName("Take Ellie out on a date").withOpenTime("6 hours from now")
Expand Down

0 comments on commit d1f39b2

Please sign in to comment.