-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyDateTime.java
More file actions
116 lines (91 loc) · 2.62 KB
/
Copy pathMyDateTime.java
File metadata and controls
116 lines (91 loc) · 2.62 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
public class MyDateTime {
MyDate date;
MyTime time;
public MyDateTime(MyDate date, MyTime time) {
this.date = date;
this.time = time;
}
@Override
public String toString() {
return date.toString() + " " + time.toString();
}
public void incrementDay() {
date.incrementDay();
}
public void incrementHour() {
time.incrementHour();
}
public void incrementHour(int diff) {
int dayDiff = time.incrementHour(diff);
if (dayDiff > 0)
date.incrementDay(dayDiff);
else
date.decrementDay(-dayDiff);
}
public void decrementHour(int diff) {
incrementHour(-diff);
}
public void incrementMinute(int diff) {
int dayDiff = time.incrementMinute(diff);
if (dayDiff > 0)
date.incrementDay(dayDiff);
else
date.decrementDay(-dayDiff);
}
public void decrementMinute(int diff) {
incrementMinute(-diff);
}
public void incrementYear(int i) {
date.incrementYear(i);
}
public void decrementDay() {
date.decrementDay();
}
public void decrementYear() {
date.decrementYear();
}
public void decrementMonth() {
date.decrementMonth();
}
public void incrementDay(int i) {
date.incrementDay(i);
}
public void decrementMonth(int i) {
date.decrementMonth(i);
}
public void decrementDay(int i) {
date.decrementDay(i);
}
public void incrementMonth(int i) {
date.incrementMonth(i);
}
public void decrementYear(int i) {
date.decrementYear(i);
}
public void incrementMonth() {
date.incrementMonth();
}
public void incrementYear() {
date.incrementYear();
}
public boolean isBefore(MyDateTime anotherDateTime) {
if (date.isBefore(anotherDateTime.date))
return true;
else if (date.isAfter(anotherDateTime.date))
return false;
if (time.isAfter(anotherDateTime.time))
return false;
return true;
}
public boolean isAfter(MyDateTime anotherDateTime) {
return !isBefore(anotherDateTime);
}
public String dayTimeDifference(MyDateTime anotherDateTime) {
int dateDifference = date.dayDifference(anotherDateTime.date);
int timeDifference = time.totalMinutesDifference(anotherDateTime.time);
int days = dateDifference;
int hours = timeDifference / 60;
int minutes = timeDifference % 60;
return days + " days, " + hours + " hours, " + minutes + " minutes";
}
}