Skip to content

Commit 52e92c5

Browse files
committed
feat: set initial implementation
1 parent 9bebc0e commit 52e92c5

28 files changed

+2348
-76
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: valid time intervals must be created and stored before any request is made.
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-addon</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: 11 additions & 4 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-addon</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>

0 commit comments

Comments
 (0)