| 25489 |
tejbeer |
1 |
package com.spice.profitmandi.dao.model;
|
|
|
2 |
|
| 30077 |
tejbeer |
3 |
import java.time.LocalDate;
|
| 25489 |
tejbeer |
4 |
import java.time.LocalDateTime;
|
| 30077 |
tejbeer |
5 |
import java.time.LocalTime;
|
| 25489 |
tejbeer |
6 |
|
| 36081 |
amit |
7 |
public class DateRangeModel implements java.io.Serializable {
|
|
|
8 |
private static final long serialVersionUID = 1L;
|
| 25489 |
tejbeer |
9 |
LocalDateTime startDate;
|
|
|
10 |
LocalDateTime endDate;
|
|
|
11 |
|
| 28596 |
amit.gupta |
12 |
public static DateRangeModel withEndDate(LocalDateTime endDate) {
|
|
|
13 |
DateRangeModel drm = new DateRangeModel();
|
|
|
14 |
drm.setEndDate(endDate);
|
|
|
15 |
return drm;
|
|
|
16 |
}
|
| 30077 |
tejbeer |
17 |
|
| 28596 |
amit.gupta |
18 |
public static DateRangeModel withStartDate(LocalDateTime startDate) {
|
|
|
19 |
DateRangeModel drm = new DateRangeModel();
|
|
|
20 |
drm.setStartDate(startDate);
|
|
|
21 |
return drm;
|
|
|
22 |
}
|
| 30077 |
tejbeer |
23 |
|
|
|
24 |
public static DateRangeModel ofDate(LocalDate date) {
|
|
|
25 |
DateRangeModel drm = new DateRangeModel();
|
|
|
26 |
drm.setStartDate(date.atStartOfDay());
|
|
|
27 |
drm.setEndDate(date.atTime(LocalTime.MAX));
|
|
|
28 |
return drm;
|
|
|
29 |
}
|
|
|
30 |
|
| 25634 |
amit.gupta |
31 |
public static DateRangeModel of(LocalDateTime startDate, LocalDateTime endDate) {
|
|
|
32 |
DateRangeModel drm = new DateRangeModel();
|
|
|
33 |
drm.setEndDate(endDate);
|
|
|
34 |
drm.setStartDate(startDate);
|
|
|
35 |
return drm;
|
|
|
36 |
}
|
| 30077 |
tejbeer |
37 |
|
| 25489 |
tejbeer |
38 |
public LocalDateTime getStartDate() {
|
|
|
39 |
return startDate;
|
|
|
40 |
}
|
|
|
41 |
|
|
|
42 |
public void setStartDate(LocalDateTime startDate) {
|
|
|
43 |
this.startDate = startDate;
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
public LocalDateTime getEndDate() {
|
|
|
47 |
return endDate;
|
|
|
48 |
}
|
|
|
49 |
|
|
|
50 |
public void setEndDate(LocalDateTime endDate) {
|
|
|
51 |
this.endDate = endDate;
|
|
|
52 |
}
|
|
|
53 |
|
| 33134 |
amit.gupta |
54 |
public boolean contains(LocalDateTime dateTime) {
|
|
|
55 |
boolean afterOrEqualStartDate = startDate == null || dateTime.isAfter(startDate) || dateTime.isEqual(startDate);
|
| 33136 |
amit.gupta |
56 |
boolean beforeOrEqualEndDate = endDate == null || dateTime.isBefore(endDate) || dateTime.isEqual(endDate);
|
| 33134 |
amit.gupta |
57 |
return afterOrEqualStartDate && beforeOrEqualEndDate;
|
|
|
58 |
}
|
|
|
59 |
|
| 29329 |
amit.gupta |
60 |
@Override
|
|
|
61 |
public String toString() {
|
|
|
62 |
return "DateRangeModel [startDate=" + startDate + ", endDate=" + endDate + "]";
|
|
|
63 |
}
|
|
|
64 |
|
|
|
65 |
@Override
|
|
|
66 |
public int hashCode() {
|
|
|
67 |
final int prime = 31;
|
|
|
68 |
int result = 1;
|
|
|
69 |
result = prime * result + ((endDate == null) ? 0 : endDate.hashCode());
|
|
|
70 |
result = prime * result + ((startDate == null) ? 0 : startDate.hashCode());
|
|
|
71 |
return result;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
@Override
|
|
|
75 |
public boolean equals(Object obj) {
|
|
|
76 |
if (this == obj)
|
|
|
77 |
return true;
|
|
|
78 |
if (obj == null)
|
|
|
79 |
return false;
|
|
|
80 |
if (getClass() != obj.getClass())
|
|
|
81 |
return false;
|
|
|
82 |
DateRangeModel other = (DateRangeModel) obj;
|
|
|
83 |
if (endDate == null) {
|
|
|
84 |
if (other.endDate != null)
|
|
|
85 |
return false;
|
|
|
86 |
} else if (!endDate.equals(other.endDate))
|
|
|
87 |
return false;
|
|
|
88 |
if (startDate == null) {
|
|
|
89 |
if (other.startDate != null)
|
|
|
90 |
return false;
|
|
|
91 |
} else if (!startDate.equals(other.startDate))
|
|
|
92 |
return false;
|
|
|
93 |
return true;
|
|
|
94 |
}
|
|
|
95 |
|
| 25489 |
tejbeer |
96 |
}
|