Subversion Repositories SmartDukaan

Rev

Rev 33134 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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