Skip to content

Commit f049d19

Browse files
committedSep 22, 2024·
fix #774 Implement a date range picker component
1 parent b9ad31e commit f049d19

File tree

7 files changed

+949
-1
lines changed

7 files changed

+949
-1
lines changed
 

‎domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarDay.java

+26-1
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,37 @@ public Element getClickableElement() {
114114
* @return true if the day is today's date, false otherwise.
115115
*/
116116
public boolean isTodayDate() {
117-
Date date = new Date();
117+
return isSameDayAs(new Date());
118+
}
119+
120+
/**
121+
* Checks if the day represents the specified date.
122+
*
123+
* @return true if the day is same year, month, and day, false otherwise.
124+
*/
125+
public boolean isSameDayAs(Date date) {
118126
return date.getYear() == this.date.getYear()
119127
&& date.getMonth() == this.date.getMonth()
120128
&& date.getDate() == this.date.getDate();
121129
}
122130

131+
public boolean isInRange(Date dateFrom, Date dateTo) {
132+
Date fromNoTime = removeTime(dateFrom);
133+
Date toNoTime = removeTime(dateTo);
134+
Date thisDayNoTime = removeTime(date);
135+
return thisDayNoTime.getTime() >= fromNoTime.getTime()
136+
&& thisDayNoTime.getTime() <= toNoTime.getTime();
137+
}
138+
139+
public static Date removeTime(Date date) {
140+
date.setHours(0);
141+
date.setMinutes(0);
142+
date.setSeconds(0);
143+
144+
date.setTime(date.getTime() / 1000 * 1000); // Set milliseconds to zero
145+
return date;
146+
}
147+
123148
/**
124149
* Checks if the day represents the currently selected date in the calendar.
125150
*

‎domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarMonth.java

+6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@
2020
import static org.dominokit.domino.ui.utils.Domino.*;
2121

2222
import elemental2.dom.HTMLDivElement;
23+
import java.util.Arrays;
2324
import java.util.Date;
25+
import java.util.List;
2426
import org.dominokit.domino.ui.elements.DivElement;
2527
import org.dominokit.domino.ui.utils.BaseDominoElement;
2628

@@ -178,6 +180,10 @@ private void updateView() {
178180
}
179181
}
180182

183+
public List<CalendarDay> getMonthViewDays() {
184+
return Arrays.asList(monthDays);
185+
}
186+
181187
/**
182188
* {@inheritDoc}
183189
*

‎domino-ui/src/main/java/org/dominokit/domino/ui/datepicker/CalendarStyles.java

+2
Original file line numberDiff line numberDiff line change
@@ -96,4 +96,6 @@ public interface CalendarStyles {
9696
CssClass dui_selected_year = () -> "dui-selected-year";
9797

9898
CssClass dui_selected_month = () -> "dui-selected-month";
99+
100+
CssClass dui_date_in_range = () -> "dui-date-in-range";
99101
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright © 2019 Dominokit
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.dominokit.domino.ui.forms;
17+
18+
import java.util.Date;
19+
import java.util.Objects;
20+
21+
public class DateRange {
22+
23+
private final Date from;
24+
private final Date to;
25+
26+
public DateRange() {
27+
this(new Date(), new Date());
28+
}
29+
30+
public DateRange(Date from, Date to) {
31+
Objects.requireNonNull(from);
32+
Objects.requireNonNull(to);
33+
this.from = from;
34+
this.to = to;
35+
}
36+
37+
public Date getFrom() {
38+
return from;
39+
}
40+
41+
public Date getTo() {
42+
return to;
43+
}
44+
45+
@Override
46+
public boolean equals(Object o) {
47+
if (this == o) {
48+
return true;
49+
}
50+
if (o == null || getClass() != o.getClass()) {
51+
return false;
52+
}
53+
DateRange dateRange = (DateRange) o;
54+
return Objects.equals(from, dateRange.from) && Objects.equals(to, dateRange.to);
55+
}
56+
57+
@Override
58+
public int hashCode() {
59+
return Objects.hash(from, to);
60+
}
61+
}

‎domino-ui/src/main/java/org/dominokit/domino/ui/forms/DateRangeBox.java

+849
Large diffs are not rendered by default.

‎domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-calendar.css

+4
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,8 @@
286286
.dui-calendar-footer {
287287
order: 80;
288288
padding: var(--dui-calendar-footer-padding);
289+
}
290+
291+
.dui-date-in-range {
292+
background: var(--dui-calendar-date-in-range-bg-color);
289293
}

‎domino-ui/src/main/resources/org/dominokit/domino/ui/public/css/domino-ui/dui-components/domino-ui-theme-default.css

+1
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,7 @@ body.dui {
12371237
--dui-calendar-today-date-border-style: solid;
12381238

12391239
--dui-calendar-selected-date-hover-color: var(--dui-color-5);
1240+
--dui-calendar-date-in-range-bg-color: var(--dui-accent-l-5);
12401241

12411242
--dui-calendar-selector-current-year-font: var(--dui-font-normal-600);
12421243
--dui-calendar-selector-current-month-font: var(--dui-font-normal-600);

0 commit comments

Comments
 (0)
Please sign in to comment.