Skip to content

Commit 30df68c

Browse files
committed
feat: set initial implementation
1 parent 9bebc0e commit 30df68c

31 files changed

+2771
-77
lines changed

README.md

Lines changed: 59 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,26 @@
44
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/template-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/template-addon)
55
[![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/template-addon)
66

7-
# Template Add-on
7+
# DateTimeRangePicker Add-on for Vaadin
88

9-
This is a template project for building new Vaadin 24 add-ons
9+
DateTimeRangePicker is a component add-on for Vaadin Framework version 14+ that assists
10+
on the creation of
11+
[time intervals](https://en.wikipedia.org/wiki/ISO_8601#Time_intervals)
12+
(a time period delimited by two instants),
13+
that conform to certain date and time constraints.
14+
It includes a DateTimeRange class with an API to operate TimeInterval class instances.
1015

11-
## Features
16+
As an example, you could set the component to handle time intervals that occur every weekend from 8:30 to 12:30 AM between the
17+
1st and 15th of May 2025. Then, you would get a DateTimeRange object and use it to consult if a certain instant is included
18+
or when will the next time interval start.
19+
20+
**Note:** current implementation **does not** support custom time zones. It uses the system's default.
1221

13-
* List the features of your add-on in here
22+
## Features
23+
- Customizable selection of date, time and days.
24+
- API to create and query time intervals. It supports two work modes:
25+
- **Lazy** mode (default): does not store time intervals and instead creates them when requested.
26+
- **Eager** mode: all valid time intervals are created and stored beforehand.
1427

1528
## Online demo
1629

@@ -27,7 +40,7 @@ Add the following dependencies in your pom.xml file:
2740
```xml
2841
<dependency>
2942
<groupId>com.flowingcode.vaadin.addons</groupId>
30-
<artifactId>template-addon</artifactId>
43+
<artifactId>date-time-range-picker</artifactId>
3144
<version>X.Y.Z</version>
3245
</dependency>
3346
```
@@ -69,13 +82,52 @@ Then, follow these steps for creating a contribution:
6982

7083
This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.
7184

72-
TEMPLATE_ADDON is written by Flowing Code S.A.
85+
DateTimeRangePicker is written by Flowing Code S.A.
7386

7487
# Developer Guide
7588

7689
## Getting started
7790

78-
Add your code samples in this section
91+
A simple instantiation.
92+
```
93+
DateTimeRangePicker addon = new DateTimeRangePicker();
94+
addon.setMinDate(LocalDate.now());
95+
addon.setMaxDate(LocalDate.now().plusDays(15));
96+
addon.setWeekDays(DayOfWeek.MONDAY, DayOfWeek.FRIDAY);
97+
```
98+
Component will have monday and friday set by default and user will not
99+
be allowed to select a start date earlier than today and an end date later than today plus fifteen days.
100+
101+
## Binding
102+
103+
Here **Pojo** has a **DateTimeRange** variable with getter and setter methods.
104+
105+
```
106+
DateTimeRangePicker addon = new DateTimeRangePicker();
107+
Binder<Pojo> binder = new Binder<>(Pojo.class);
108+
binder.forField(addon).bind(Pojo::getDateTimeRange, Pojo::setDateTimeRange);
109+
binder.setBean(pojo);
110+
```
111+
After a successful validation you can use the return value to make queries.
112+
113+
```
114+
TimeInterval interval = pojo.getDateTimeRange().getNextInterval();
115+
boolean includes = interval != null && interval.includes(LocalDateTime.now());
116+
```
117+
118+
## DateTimeRange modes
119+
As described above, by default **TimeInterval**
120+
instances are not stored but created and returned when needed. This is called **Lazy** mode.
121+
122+
When the dataset is small, switching to **Eager** mode may yield better results, as the objects are created all at once.
123+
If you do, remember to call refresh() whenever the state of the DateTimeRange object changes.
124+
125+
126+
```
127+
dateTimeRange.setFetchMode(FetchMode.EAGER);
128+
dateTimeRange.refresh();
129+
```
130+
79131

80132
## Special configuration when using Spring
81133

pom.xml

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.flowingcode.vaadin.addons</groupId>
8-
<artifactId>template-addon</artifactId>
8+
<artifactId>date-time-range-picker</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
10-
<name>Template Add-on</name>
11-
<description>Template Add-on for Vaadin Flow</description>
10+
<name>DateTimeRangePicker</name>
11+
<description>DateTimeRangePicker Vaadin Add-on</description>
1212
<url>https://www.flowingcode.com/en/open-source/</url>
1313

1414
<properties>
15-
<vaadin.version>24.4.6</vaadin.version>
15+
<vaadin.version>24.4.7</vaadin.version>
1616
<selenium.version>4.10.0</selenium.version>
1717
<maven.compiler.source>17</maven.compiler.source>
1818
<maven.compiler.target>17</maven.compiler.target>
@@ -156,6 +156,13 @@
156156
<version>5.9.1</version>
157157
<scope>test</scope>
158158
</dependency>
159+
160+
<dependency>
161+
<groupId>com.flowingcode.vaadin.addons</groupId>
162+
<artifactId>day-of-week-selector-addon</artifactId>
163+
<version>1.0.1</version>
164+
</dependency>
165+
159166
</dependencies>
160167

161168
<build>
@@ -495,7 +502,7 @@
495502
<exclude>**/it/*</exclude>
496503
<exclude>**/DemoView.class</exclude>
497504
<exclude>**/DemoLayout.class</exclude>
498-
<exclude>**/AppShellConfiguratorImpl.class</exclude>
505+
<exclude>**/com.flowingcode.vaadin.addons.AppShellConfiguratorImpl.class</exclude>
499506
</excludes>
500507
</configuration>
501508
</execution>
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
/*-
2+
* #%L
3+
* DateTimeRangePicker Add-on
4+
* %%
5+
* Copyright (C) 2025 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
package com.flowingcode.vaadin.addons.dtrp.api;
21+
22+
import java.time.DayOfWeek;
23+
import java.time.Duration;
24+
import java.time.LocalDate;
25+
import java.time.LocalTime;
26+
import java.util.List;
27+
28+
/**
29+
* {@link com.flowingcode.vaadin.addons.dtrp.ui.DateTimeRangePicker DateTimeRangePicker} public API
30+
*
31+
* @author Izaguirre, Ezequiel
32+
*/
33+
public interface DTRPService {
34+
35+
/**
36+
* Changes this component's visibility state
37+
*/
38+
void setVisible(boolean visible);
39+
40+
/**
41+
* Changes all the component's fields read only state
42+
*/
43+
void setReadOnly(boolean readOnly);
44+
45+
/**
46+
* Sets the maximum days distance between start and end dates
47+
*/
48+
void setMaxDaysSpan(int max);
49+
50+
/**
51+
* Sets the minimum start date
52+
*/
53+
void setMinDate(LocalDate date);
54+
55+
/**
56+
* Sets the maximum end date
57+
*/
58+
void setMaxDate(LocalDate date);
59+
60+
/**
61+
* Sets the minimum start time for any time interval
62+
*/
63+
void setMinTime(LocalTime time);
64+
65+
/**
66+
* Sets the maximum end time for any time interval
67+
*/
68+
void setMaxTime(LocalTime time);
69+
70+
/**
71+
* Sets the selected week days
72+
*/
73+
void setWeekDays(DayOfWeek... weekDays);
74+
75+
/**
76+
* Sets which will be the starting or left-most week day
77+
*/
78+
void setFirstWeekDay(DayOfWeek weekDay);
79+
80+
/**
81+
* Changes the date pickers read only state
82+
*/
83+
void setDatesReadOnly(boolean readOnly);
84+
85+
/**
86+
* Changes the date pickers visibility state
87+
*/
88+
void setDatesVisible(boolean visible);
89+
90+
/**
91+
* Changes the day pickers read only state
92+
*/
93+
void setDaysReadOnly(boolean readOnly);
94+
95+
/**
96+
* Changes the day pickers visibility state
97+
*/
98+
void setDaysVisible(boolean visible);
99+
100+
/**
101+
* Changes the time pickers read only state
102+
*/
103+
void setTimesReadOnly(boolean readOnly);
104+
105+
/**
106+
* Changes the time pickers visibility state
107+
*/
108+
void setTimesVisible(boolean visible);
109+
110+
/**
111+
* Changes the left line indicator visibility state
112+
*/
113+
void setIndicatorVisible(boolean visible);
114+
115+
/**
116+
* Sets the date pickers title
117+
*/
118+
void setDatesTitle(String text);
119+
120+
/**
121+
* Sets the days picker title
122+
*/
123+
void setDaysTitle(String text);
124+
125+
/**
126+
* Sets the time pickers title
127+
*/
128+
void setTimesTitle(String text);
129+
130+
/**
131+
* Sets the minimum time separation for the
132+
* {@link com.vaadin.flow.component.timepicker.TimePicker time pickers' list}
133+
*/
134+
void setTimeStep(Duration step);
135+
136+
/**
137+
* Sets the text for the days' selector
138+
*/
139+
void setDaysInitials(List<String> initials);
140+
141+
/**
142+
* Sets the text for the time chips
143+
*/
144+
void setTimeChipsInitials(String morning, String afternoon, String all);
145+
146+
/**
147+
* Sets the text for days chips
148+
*/
149+
void setDaysChipsInitials(String weekdays, String weekend, String all);
150+
}

0 commit comments

Comments
 (0)