Skip to content

Commit

Permalink
fix #774 Implement a date range picker component
Browse files Browse the repository at this point in the history
  • Loading branch information
vegegoku committed Sep 22, 2024
1 parent b9ad31e commit f049d19
Show file tree
Hide file tree
Showing 7 changed files with 949 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,37 @@ public Element getClickableElement() {
* @return true if the day is today's date, false otherwise.
*/
public boolean isTodayDate() {
Date date = new Date();
return isSameDayAs(new Date());
}

/**
* Checks if the day represents the specified date.
*
* @return true if the day is same year, month, and day, false otherwise.
*/
public boolean isSameDayAs(Date date) {
return date.getYear() == this.date.getYear()
&& date.getMonth() == this.date.getMonth()
&& date.getDate() == this.date.getDate();
}

public boolean isInRange(Date dateFrom, Date dateTo) {
Date fromNoTime = removeTime(dateFrom);
Date toNoTime = removeTime(dateTo);
Date thisDayNoTime = removeTime(date);
return thisDayNoTime.getTime() >= fromNoTime.getTime()
&& thisDayNoTime.getTime() <= toNoTime.getTime();
}

public static Date removeTime(Date date) {
date.setHours(0);
date.setMinutes(0);
date.setSeconds(0);

date.setTime(date.getTime() / 1000 * 1000); // Set milliseconds to zero
return date;
}

/**
* Checks if the day represents the currently selected date in the calendar.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
import static org.dominokit.domino.ui.utils.Domino.*;

import elemental2.dom.HTMLDivElement;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import org.dominokit.domino.ui.elements.DivElement;
import org.dominokit.domino.ui.utils.BaseDominoElement;

Expand Down Expand Up @@ -178,6 +180,10 @@ private void updateView() {
}
}

public List<CalendarDay> getMonthViewDays() {
return Arrays.asList(monthDays);
}

/**
* {@inheritDoc}
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,6 @@ public interface CalendarStyles {
CssClass dui_selected_year = () -> "dui-selected-year";

CssClass dui_selected_month = () -> "dui-selected-month";

CssClass dui_date_in_range = () -> "dui-date-in-range";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* Copyright © 2019 Dominokit
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.dominokit.domino.ui.forms;

import java.util.Date;
import java.util.Objects;

public class DateRange {

private final Date from;
private final Date to;

public DateRange() {
this(new Date(), new Date());
}

public DateRange(Date from, Date to) {
Objects.requireNonNull(from);
Objects.requireNonNull(to);
this.from = from;
this.to = to;
}

public Date getFrom() {
return from;
}

public Date getTo() {
return to;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
DateRange dateRange = (DateRange) o;
return Objects.equals(from, dateRange.from) && Objects.equals(to, dateRange.to);
}

@Override
public int hashCode() {
return Objects.hash(from, to);
}
}
Loading

0 comments on commit f049d19

Please sign in to comment.