Skip to content
Snippets Groups Projects
Commit 7b31c261 authored by Rafi's avatar Rafi
Browse files

Made changes to the constructor class so parsing is done here, and that the date is also stored.

parent baa36d72
No related branches found
No related tags found
1 merge request!6Changed update implementation for employees so rather than sending the whole...
package com.example.schedulerapp; package com.example.schedulerapp;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
public class Shift { public class Shift {
private int EmployeeID; private int EmployeeID;
private String date;
private LocalDateTime start; private LocalDateTime start;
private LocalDateTime end; private LocalDateTime end;
private boolean available; private boolean available;
private int shiftID; private int shiftID;
//todo: error checking on start/end? (end cannot be before start) //todo: error checking on start/end? (end cannot be before start)
public Shift(int EmpID, LocalDateTime start, LocalDateTime end, int shiftID){ public Shift(String shiftData){
this.EmployeeID = EmpID; try {
this.start = start; DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-ddHHmm");
this.end = end; String[] dataSplit = shiftData.split("\\.");
this.available = false; this.EmployeeID = Integer.parseInt(dataSplit[0]);
this.shiftID = shiftID; this.shiftID = Integer.parseInt(dataSplit[4]);
if (dataSplit[2].length() == 3) dataSplit[2] = "0" + dataSplit[2];
if (dataSplit[3].length() == 3) dataSplit[3] = "0" + dataSplit[3];
this.start = LocalDateTime.parse(dataSplit[1] + dataSplit[2], formatter);
this.end = LocalDateTime.parse(dataSplit[1] + dataSplit[3], formatter);
this.date = dataSplit[1];
this.available = false;
} catch (Exception exception) {
exception.printStackTrace();
}
} }
public int getEmployeeID() { public int getEmployeeID() {
...@@ -30,6 +41,10 @@ public class Shift { ...@@ -30,6 +41,10 @@ public class Shift {
return end; return end;
} }
public String getDate() {
return date;
}
public boolean isAvailable() { public boolean isAvailable() {
return available; return available;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment