- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyDateTime.java
More file actions
Latest commit
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
publicclassMyDateTime {
MyDatedate;
MyTimetime;
publicMyDateTime(MyDatedate, MyTimetime) {
this.date = date;
this.time = time;
}
@Override
publicStringtoString() {
returndate.toString() + " " + time.toString();
}
publicvoidincrementDay() {
date.incrementDay();
}
publicvoidincrementHour() {
time.incrementHour();
}
publicvoidincrementHour(intdiff) {
intdayDiff = time.incrementHour(diff);
if (dayDiff > 0)
date.incrementDay(dayDiff);
else
date.decrementDay(-dayDiff);
}
publicvoiddecrementHour(intdiff) {
incrementHour(-diff);
}
publicvoidincrementMinute(intdiff) {
intdayDiff = time.incrementMinute(diff);
if (dayDiff > 0)
date.incrementDay(dayDiff);
else
date.decrementDay(-dayDiff);
}
publicvoiddecrementMinute(intdiff) {
incrementMinute(-diff);
}
publicvoidincrementYear(inti) {
date.incrementYear(i);
}
publicvoiddecrementDay() {
date.decrementDay();
}
publicvoiddecrementYear() {
date.decrementYear();
}
publicvoiddecrementMonth() {
date.decrementMonth();
}
publicvoidincrementDay(inti) {
date.incrementDay(i);
}
publicvoiddecrementMonth(inti) {
date.decrementMonth(i);
}
publicvoiddecrementDay(inti) {
date.decrementDay(i);
}
publicvoidincrementMonth(inti) {
date.incrementMonth(i);
}
publicvoiddecrementYear(inti) {
date.decrementYear(i);
}
publicvoidincrementMonth() {
date.incrementMonth();
}
publicvoidincrementYear() {
date.incrementYear();
}
publicbooleanisBefore(MyDateTimeanotherDateTime) {
if (date.isBefore(anotherDateTime.date))
returntrue;
elseif (date.isAfter(anotherDateTime.date))
returnfalse;
if (time.isAfter(anotherDateTime.time))
returnfalse;
returntrue;
}
publicbooleanisAfter(MyDateTimeanotherDateTime) {
return !isBefore(anotherDateTime);
}
publicStringdayTimeDifference(MyDateTimeanotherDateTime) {
intdateDifference = date.dayDifference(anotherDateTime.date);
inttimeDifference = time.totalMinutesDifference(anotherDateTime.time);
intdays = dateDifference;
inthours = timeDifference / 60;
intminutes = timeDifference % 60;
returndays + " days, " + hours + " hours, " + minutes + " minutes";
}
}