Skip to content
This repository was archived by the owner on Dec 4, 2020. It is now read-only.

Commit 1cab6a2

Browse files
committed
Add differenceCalculator in Controller
1 parent 4d5c581 commit 1cab6a2

File tree

1 file changed

+32
-16
lines changed

1 file changed

+32
-16
lines changed

tracker/src/main/java/com/hanahs/tracker/MainScreenController.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import java.io.IOException;
44
import java.security.GeneralSecurityException;
5+
import java.text.SimpleDateFormat;
56
import java.time.LocalDate;
7+
import java.util.ArrayList;
68
import java.util.List;
79
import java.util.Optional;
810

@@ -29,11 +31,12 @@ public class MainScreenController {
2931
@FXML private GridPane calendarGrid;
3032
@FXML private ListView<AssignmentProvider> accountList;
3133
@FXML private Label scheduleDescriptionLabel;
32-
@FXML private ListView scheduleList;
34+
@FXML private ListView<String> scheduleList;
3335
@FXML Spinner<Integer> scheduleDays;
3436
private int currentSelectionY = -1;
3537
private int currentSelectionX = -1;
3638
private AssignmentManager manager;
39+
private List<List<Assignment>> schedule;
3740

3841

3942
private Node getNodeFromGridPane(int col, int row) {
@@ -69,26 +72,39 @@ public void handle(MouseEvent event) {
6972
Label lastSelected = (Label)lastSelectedNode;
7073
lastSelected.getStyleClass().remove("calendar-date-selected");
7174
}
72-
label.getProperties().get("Date");
73-
int days = Optional.ofNullable((Integer)scheduleDays.getValue()).orElse(0);
74-
try {
75-
List<List<Assignment>> schedule = manager.scheduleAssignments(days, 5);
76-
} catch (IOException e) {
77-
// TODO Auto-generated catch block
78-
e.printStackTrace();
79-
String titleText = "오류 발생";
80-
String contentText = "스케쥴을 불러오는 과정에서 오류가 발생했습니다.";
81-
showErrorAlert(titleText, contentText);
82-
83-
}
84-
accountList.setItems(FXCollections.observableArrayList(manager.getProviders()));
8575
}
8676
Label sender = (Label)event.getSource();
8777
sender.getStyleClass().add("calendar-date-selected");
8878
currentSelectionX = GridPane.getColumnIndex(sender);
8979
currentSelectionY = GridPane.getRowIndex(sender);
80+
81+
if (schedule == null || schedule.size() == 0) return;
82+
LocalDate selectedDate = (LocalDate) sender.getProperties().get("date");
83+
LocalDate today = LocalDate.now();
84+
LocalDate endOfSchedule = today.plusDays(schedule.size() - 1);
85+
List<String> assignments = new ArrayList<>();
86+
if (today.isAfter(selectedDate)) {
87+
scheduleList.setItems(FXCollections.observableArrayList(assignments));
88+
return;
89+
}
90+
if (endOfSchedule.isBefore(selectedDate)) {
91+
scheduleList.setItems(FXCollections.observableArrayList(assignments));
92+
return;
93+
}
94+
public void differenceCalculator() throws ParseException {
95+
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy", Locale.ENGLISH);
96+
Date firstDate = sdf.parse(today);
97+
Date secondDate = sdf.parse(selectedDate);
98+
long diffInMillies = Math.abs(secondDate.getTime() - firstDate.getTime());
99+
long diff = TimeUnit.DAYS.convert(diffInMillies, TimeUnit.MILLISECONDS);
100+
101+
assertEquals(6, diff);
102+
}
103+
for(String assigns : assignments) {
104+
listView.setItems(FXCollections.observableArrayList("assigns", diff));
105+
}
90106
}
91-
}
107+
};
92108
label.addEventHandler(MouseEvent.MOUSE_CLICKED, handler);
93109
calendarGrid.add(label, x, y + 1);
94110
current = current.plusDays(1);
@@ -149,7 +165,7 @@ private void updateAccountList() {
149165
@FXML public void scheduleAssignmentAction() {
150166
try {
151167
int days = Optional.ofNullable((Integer)scheduleDays.getValue()).orElse(0);
152-
List<List<Assignment>> schedule = manager.scheduleAssignments(days, 5);
168+
schedule = manager.scheduleAssignments(days, 5);
153169
} catch(IOException e) {
154170
e.printStackTrace();
155171
String titleText = "오류 발생";

0 commit comments

Comments
 (0)