Skip to content

Commit f3f7862

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

28 files changed

+2364
-83
lines changed

README.md

Lines changed: 86 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,43 @@
1-
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/template-add-on)
2-
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/template-add-on.svg)](https://vaadin.com/directory/component/template-add-on)
3-
[![Build Status](https://jenkins.flowingcode.com/job/template-addon/badge/icon)](https://jenkins.flowingcode.com/job/template-addon)
4-
[![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)
5-
[![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/template-addon)
1+
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/date-time-range-picker-add-on)
2+
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/template-add-on.svg)](https://vaadin.com/directory/component/date-time-range-picker-add-on)
3+
[![Build Status](https://jenkins.flowingcode.com/job/template-addon/badge/icon)](https://jenkins.flowingcode.com/job/date-time-range-picker-addon)
4+
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/template-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/date-time-range-picker-addon)
5+
[![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/date-time-range-picker-addon)
66

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

9-
This is a template project for building new Vaadin 24 add-ons
9+
A component to create [Time Intervals](https://en.wikipedia.org/wiki/ISO_8601#Time_intervals) (_a time period defined by start and end instants_) inside a time frame.
1010

11-
## Features
11+
You use the UI to define time and date ranges in which the time intervals should be created, and then call the API to operate them.
12+
13+
As an example, you could set it to create an interval **every weekend** from **8:30 to 12:30 AM** between the
14+
**1st and 15th of May 2025**.<br>Then, you can make the following queries:
15+
16+
1. How many intervals will be created? (4)
17+
2. Starting from today, when will the next interval occur?
18+
3. Is the 7th of May at 9:15 AM included in any interval? (It's not)
19+
- How about the 5th of May at 9:00 AM? (Yes)
20+
4. How many intervals will have passed after the 9th of May? (2)
21+
5. How many intervals will remain after the 5th of May at 12:45? (3)
22+
23+
... and more
1224

13-
* List the features of your add-on in here
25+
> [!NOTE]
26+
> Custom time zones are currently not supported. It will fall back to the system's default.
27+
28+
## Features
29+
- Customizable selection of date, time and days.
30+
- API to create and query time intervals. It supports two work modes:
31+
- **Lazy** (<ins>default</ins>): will not store time intervals and instead supply (create) them on demand.
32+
- **Eager**: will create and store them beforehand so they can be reused on every request.
1433

1534
## Online demo
1635

17-
[Online demo here](http://addonsv24.flowingcode.com/template)
36+
[Online demo here](http://addonsv24.flowingcode.com/date-time-range-picker)
1837

1938
## Download release
2039

21-
[Available in Vaadin Directory](https://vaadin.com/directory/component/template-add-on)
40+
[Available in Vaadin Directory](https://vaadin.com/directory/component/date-time-range-picker-add-on)
2241

2342
### Maven install
2443

@@ -27,7 +46,7 @@ Add the following dependencies in your pom.xml file:
2746
```xml
2847
<dependency>
2948
<groupId>com.flowingcode.vaadin.addons</groupId>
30-
<artifactId>template-addon</artifactId>
49+
<artifactId>date-time-range-picker-addon</artifactId>
3150
<version>X.Y.Z</version>
3251
</dependency>
3352
```
@@ -69,13 +88,66 @@ Then, follow these steps for creating a contribution:
6988

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

72-
TEMPLATE_ADDON is written by Flowing Code S.A.
91+
DateTimeRangePicker is written by Flowing Code S.A.
7392

7493
# Developer Guide
7594

7695
## Getting started
7796

78-
Add your code samples in this section
97+
```
98+
DateTimeRangePicker addon = new DateTimeRangePicker(); (1)
99+
addon.setMinDate(LocalDate.now()); (2)
100+
addon.setMaxDate(LocalDate.now().plusDays(15)); (2)
101+
addon.setWeekDays(DayOfWeek.MONDAY, DayOfWeek.FRIDAY); (3)
102+
```
103+
- (1) Instantiation.
104+
- (2) Date range selection will be constraint between **today** and **fifteen** days later.
105+
- (3) Component will have **Monday** and **Friday** selected by default.
106+
107+
## Binding
108+
109+
The API is exposed through the **DateTimeRange** class.
110+
111+
```
112+
DateTimeRangePicker addon = new DateTimeRangePicker();
113+
Binder<Pojo> binder = new Binder<>(Pojo.class); (1)
114+
binder.forField(addon).bind(Pojo::getDateTimeRange, Pojo::setDateTimeRange); (2)
115+
binder.setBean(pojo); (3)
116+
```
117+
- (1) The **Pojo** class is binded using its getter and setter methods (2).
118+
- (2) The **DateTimeRangePicker** is binded. Its [value](https://vaadin.com/api/platform/current/com/vaadin/flow/component/HasValue.html) can be operated now.
119+
- (3) The **DateTimeRange** instance is saved in the **Pojo** class or returned from it.
120+
121+
122+
You can operate time intervals with the **DateTimeRange** class, which acts as a holder.
123+
124+
```
125+
TimeInterval interval = pojo.getDateTimeRange().getNextInterval(); (1)
126+
boolean includes = pojo.getDateTimeRange().includes(LocalDateTime.now()); (2)
127+
```
128+
- (1) "Starting from today, when will the next interval occur?"
129+
- (2) "Is today included in any interval?"
130+
131+
You can also use the **TimeInterval** instance directly.
132+
133+
```
134+
boolean includes = interval != null && interval.includes(LocalDateTime.now());
135+
```
136+
137+
## DateTimeRange modes
138+
By default, **TimeInterval** instances are not stored, but created and returned when needed.<br>
139+
This is called **Lazy** mode and tries to optimize memory usage.
140+
141+
When the dataset is small, switching to **Eager** mode may yield better results, as objects are created all at once and reused.<br>
142+
A call to ``DateTimeRange::refresh()`` must be done beforehand to ensure the content is present and updated.<br>
143+
You will need to call this method again if you modify the date and time range constraints.
144+
145+
146+
```
147+
dateTimeRange.setFetchMode(DateTimeRangePickerFetchMode.EAGER);
148+
dateTimeRange.refresh();
149+
```
150+
79151

80152
## Special configuration when using Spring
81153

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)