-
Notifications
You must be signed in to change notification settings - Fork 0
/
Time.java
74 lines (60 loc) · 2.27 KB
/
Time.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package tss;
public class Time {
/**
* This class will check the timings of the performances
*/
public Time() {
}
/**
* This method extracts the start time from the time and date format
* and then turns it into a integer format
* @param startTime The start time and date of performance
* @return The start time of the performance in integer format
*/
public static int getStartTime(String startTime) {
//Splits the string into two parts, one containing the hours and
//one containing the minutes
String[] hoursMinutes = startTime.split(":");
String minutesString = hoursMinutes[1];
String hoursString = hoursMinutes[0];
//Take the last two characters from the hours string as we do
//not want the date part of the string
hoursString = hoursString.substring(hoursString.length() - 2);
//Concatenate the two strings
String totalTime = hoursString + minutesString;
return Integer.parseInt(totalTime);
}
/**
* This method works out the end time for the performance from
* the start time and duration. Also in the process converts
* the start time to integer format from string format
* @param startTime The start time and date of performance
* @param duration The duration of the performance
* @return
*/
public static int getEndTime(String startTime, int duration) {
String[] hoursMinutes = startTime.split(":");
String minutesString = hoursMinutes[1];
String hoursString = hoursMinutes[0];
hoursString = hoursString.substring(hoursString.length() - 2);
String totalTime = hoursString + minutesString;
int startTimeInt = Integer.parseInt(totalTime);
int endTimeInt = startTimeInt+((duration / 60)*100)+(duration % 60);
return endTimeInt;
}
/**
* This method checks if the two dates of the performances in
* question are the same
* @param performance1 The first performances to compare.
* @param performance2 The second performance to compare.
* @return true if they are the same date, false otherwise
*/
public static boolean sameDate(String performance1, String performance2) {
String[] date1 = performance1.split("T");
String[] date2 = performance2.split("T");
if(date1[0].equals(date2[0])) {
return true;
}
return false;
}
}